相关疑难解决方法(0)

ArrayIndexOutOfBoundsException,包含用于ListView中多个视图的自定义Android适配器

我正在尝试为ListView创建自定义适配器,因为列表中的每个项目都可以有不同的视图(链接,切换或无线电组),但是当我尝试运行使用ListView的Activity时,我收到错误,该应用程序停止.该应用程序针对Android 1.6平台.

代码:

public class MenuListAdapter extends BaseAdapter {
 private static final String LOG_KEY = MenuListAdapter.class.getSimpleName();

 protected List<MenuItem> list;
 protected Context ctx;
 protected LayoutInflater inflater;

 public MenuListAdapter(Context context, List<MenuItem> objects) {
  this.list = objects;
  this.ctx = context;
  this.inflater = (LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 }

 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  Log.i(LOG_KEY, "Position: " + position + "; convertView = " + convertView + "; parent=" + parent);
  MenuItem item = list.get(position);
  Log.i(LOG_KEY, "Item=" + item );

        if (convertView == …
Run Code Online (Sandbox Code Playgroud)

android listview exception adapter

185
推荐指数
2
解决办法
3万
查看次数

标签 统计

adapter ×1

android ×1

exception ×1

listview ×1