使用DB游标查询自定义适配器

我正在使用以下自定义适配器从数据库游标填充我的列表控件。 我无法理解为什么这个代码在构造函数中特别是在调用super时崩溃了。

public class ListAdaptor extends SimpleCursorAdapter {

    private Cursor dataCursor;
    private LayoutInflater mInflater;

    class ViewHolder {

        public TextView label   = null;
        public CheckBox chkBx   = null;
        public TextView price   = null;
        public TextView weight  = null;
    }


    //constructor
    public ListAdaptor(Context context, int layout, Cursor dataCursor, String[] from, int[] to) {

        super(context, layout, dataCursor, from, to);
        this.dataCursor = dataCursor;
        mInflater = LayoutInflater.from(context);
    }

    public View getView(int position, View convertView, ViewGroup parent) {

       //A ViewHolder keeps references to children views to avoid unneccessary calls
       //to findViewById() on each row.
        ViewHolder holder;

       //When convertView is not null, we can reuse it directly, there is no need
       //to reinflate it. We only inflate a new View when the convertView supplied
       //by ListView is null.

        if (convertView == null) {

           //Inflate the view
            convertView = mInflater.inflate(R.layout.listviewlyt, null);

           //Get the ID's of the views
            TextView tmpLbl     = (TextView)convertView.findViewById(R.id.label);
            CheckBox tmpChkBx   = (CheckBox)convertView.findViewById(R.id.chkbox);
            TextView tmpPrc     = (TextView)convertView.findViewById(R.id.labelPrice);
            TextView tmpWt      = (TextView)convertView.findViewById(R.id.labelWt);


           //Creates a ViewHolder and store references to the two children views
           //we want to bind data to.
            holder = new ViewHolder();

            holder.label    = tmpLbl;
            holder.chkBx    = tmpChkBx;
            holder.price   = tmpPrc;
            holder.weight  = tmpWt;

           //Set the Tag
            convertView.setTag(holder);

        } 
        else {
           //Get the ViewHolder back to get fast access to the TextView
           //and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }

       //Bind the data efficiently with the holder.
       //Cursor to current item

        dataCursor.moveToPosition(position);
        String keyWrd = dataCursor.getString(2);
        String price  = dataCursor.getString(3);

        TextView labelRef   = holder.label;
        CheckBox chbxRef    = holder.chkBx;
        TextView labelPrc   = holder.price;
        TextView labelWt    = holder.weight;

        labelRef.setText(keyWrd);
        labelPrc.setText(price);
        //chbxRef.setChecked(refObj.flag);
        //labelWt.setText(refObj.wt);

        return convertView;
    }
}

有人可以帮我找到原因吗?

0
什么是例外?
额外 作者 Rajdeep Dua,
请发布错误日志。
额外 作者 hovanessyan,
线程[<3>主要](已暂停)ActivityThread.performLaunchActivity(ActivityThread $ Activ&zwnj; ityRecord,Intent)行:2494 ActivityThread.handleLaunchActivity(ActivityThread $ Activi&zwnj; tyRecord,Intent)行:2512 ActivityThread.access $ 2200(ActivityThread,ActivityThread $ ActivityRecord,Intent)行:119 ActivityThread $ H.handleMessage(消息)行:1863 ActivityThread $ H(Handler).dispatchMessage(消息)行:99 Looper.loop()行:123 ActivityThread.main(String [])行:4363
额外 作者 Phoenix,

1 答案

最有可能这条线可能会给出问题

mInflater = LayoutInflater.from(context);
0
额外
谢谢Rajdeep。我想出来了。问题是我没有在我的数据库中使用_Id,因为光标不起作用。此外,我发现从CusrorAdaptor扩展适配器类并覆盖BindView和NewView成员函数更容易。
额外 作者 Phoenix,
android Discuss | 辣鸡谷歌毁我信仰
android Discuss | 辣鸡谷歌毁我信仰
1 575 参与者

日常闲聊水 和其他任意讨论聊天瞎扯 只要不是 Sticker Spam 什么都好 少喷政治 @daigua 个人频道 | 因阙丝汀 @DuangCN 瓜体中文 | 语言包 @Nekogram 一只需要关怀的第三方客户端 @AndroidMemory 语录 | 嘿嘿嘿 combot.org/chat/-1001054976571 水表