如何处理错误列' _id'在Android自定义光标适配器中不存在

时间:2016-04-22 11:03:49

标签: android android-sqlite android-cursoradapter

我有一个带有_id列的表,它在几个查询中正常使用我使用新的自定义游标适配器执行另一个查询,如下所示

public class TimeOutCAdapter extends CursorAdapter{
View retView;
Context context;
Cursor cur;
private DBHelper mHelper;
public TimeOutCAdapter(Context context, Cursor c)
{
    super(context, c);
    this.context =context;
    this.cur =c;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    retView = inflater.inflate(R.layout.timeout_item, parent, false);
    return retView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
    List<TextView> txtStatsTimeout;
    final int[] statsTimeout =
            {
                   R.id.txtTimeOut1,R.id.txtTimeOut2,R.id.txtTimeOut3,R.id.txtTimeOut4,R.id.txtTimeOut5,R.id.txtTimeOut6,R.id.txtTimeOut7,
                   R.id.txtTimeOut8,R.id.txtTimeOut9,R.id.txtTimeOut10,R.id.txtTimeOut11,R.id.txtTimeOut12
            };
    txtStatsTimeout = new ArrayList<TextView>(); //List with textviews
    for (int id : statsTimeout) {
        TextView txtView = (TextView) view.findViewById(id);
        txtStatsTimeout.add(txtView);
    }
   view.findViewById(R.id.txtTimeOut1);

    textViewName.setText(cursor.getString(cursor.getColumnIndex("gameroster_name")));

    for(int i=0;i<txtStatsTimeout.size();i++)
    {
        txtStatsTimeout.get(i).setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i))));
    }
    view.setTag(cursor.getPosition());
}

}

我在super(context,c)

上的类声明中得到错误

1 个答案:

答案 0 :(得分:0)

是的,上面的内容是正确的,但是我们应该小心从哪个表中得到_id所以我做了如上所述的customer_id AS _id而不仅仅是_id