0
こんにちは私はAssymetricGridViewの実装に問題がありますが、まだクラッシュしていますが、私のアダプターで正しく実装する方法が分かりません。最初はAndroid実装AsymmetricGridView
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)
私のコード
<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<ItemCategory> 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);
とアダプタコード
public class AdapterCategory extends ArrayAdapter<ItemCategory> {
ItemCategory object;
private Activity activity;
private List<ItemCategory> 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;
}
}