我正在使用SepatateListAdapter
这篇文章的部分中的列表视图中显示一些数据
我的代码如下:
ListView photos_list = (ListView) findViewById(R.id.photos_list);
separate_adapter = new SeparatedListAdapter(this);
AddedPhotosAdapter one_adapter = new AddedPhotosAdapter(this, R.layout.row_acc_info , photos_instagram);
separate_adapter.addSection(" Section1 ", one_adapter);
AddedPhotosAdapter two_adapter = new AddedPhotosAdapter(this, R.layout.row_acc_info , photos_fb);
separate_adapter.addSection(" Section2 ", two_adapter);
AddedPhotosAdapter three_adapter = new AddedPhotosAdapter(this, R.layout.row_acc_info , photos_picasa);
separate_adapter.addSection(" Section3 ", thee_adapter);
photos_list.setAdapter(separate_adapter);
我也注册了上下文菜单
registerForContextMenu(photos_list);
这是上下文菜单创建和从菜单中选择的项目的代码
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (v.getId() == R.id.photos_list) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
Log.i(TAG, "*********position******" +info.position);
Object item = separate_adapter.getItem(info.position);
PhotosInfo total = (PhotosInfo) item ;
menu.setHeaderTitle(total.getPhoto_Name());
menu.add(0, 1, 0, "Delete photo account");
menu.add(0, 2, 1, "Cancel");
}
}
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
if (item.getGroupId() == 0) {
switch(item.getItemId()) {
case 1:
break;
case 2:
break;
}
}
return super.onContextItemSelected(item);
}
这是我用于带有separatelistadapter的列表视图的代码我在这里收到这个错误FATAL EXCEPTION: main
E/AndroidRuntime(9228): java.lang.ClassCastException: java.lang.String
E/AndroidRuntime(9228): at com.colours.pipemedia.photos.PhotosMain.onCreateContextMenu(PhotosMain.java:170)
这是导致代码错误的行
PhotosInfo total = (PhotosInfo) item ;
我将此代码用于单个适配器,它工作正常。但是如果我与单独的列表适配器一起使用它会给出错误。这个要求的解决方案是什么?