felipecsl / AsymmetricGridView

Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span
http://felipecsl.com/AsymmetricGridView
MIT License
1.84k stars 431 forks source link

Implement library #60

Closed Gabik7 closed 8 years ago

Gabik7 commented 8 years ago

Hello i have some problem with implementation of AssymetricGridView it still crashing but i dont know what is wrong how to implement it correctly with my adapter there is error Link to AssymetricGridView library. Thank you

Adapter must be an instance of AsymmetricGridViewAdapter at com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView.setAdapter(AsymmetricGridView.java:71) at com.gabriel.movies.fragment.MainFragment.render(MainFragment.java:140) at com.gabriel.movies.fragment.MainFragment$MyTask.onPostExecute(MainFragment.java:228) at com.gabriel.movies.fragment.MainFragment$MyTask.onPostExecute(MainFragment.java:161) My code

<com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent" />

AsymmetricGridView gridview; List list; AdapterCategory adapter;

gridview = (AsymmetricGridView) mRootView.findViewById(R.id.gridView1);
gridview.setRequestedColumnWidth(Utils.dpToPx(getActivity(), 120));

list = new ArrayList<ItemCategory>();

adapter = new AdapterCategory(getActivity(), R.layout.fragment_worcipe_main_item, list);
gridview.setAdapter(adapter);

and adapter code

public class AdapterCategory extends ArrayAdapter { ItemCategory object; private Activity activity; private List item; private int row;

 public AdapterCategory(Activity act, int resource, List<ItemCategory> arrayList) {
        super(act, resource, arrayList);
        this.activity = act;
        this.row = resource;
        this.item = arrayList;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder;

        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(row, null);
            holder = new ViewHolder();
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        if ((item == null) || ((position + 1) > item.size()))
            return view;

        object = item.get(position);

        holder.title = (TextView) view.findViewById(R.id.category_title);
        holder.image = (ImageView) view.findViewById(R.id.category_image);

        holder.title.setText(object.getCategoryName());

        Picasso.with(getContext()).load(RecipeConfig.SERVER_URL + "/upload/" +
                object.getCategoryImageurl()).placeholder(R.drawable.ic_thumbnail).into(holder.image);

        return view;
    }

    public class ViewHolder {
        public TextView title;
        public ImageView image;

    }
}
felipecsl commented 8 years ago

Your AdapterCategory needs to extend AsymmetricGridViewAdapter