【发布时间】:2011-02-19 22:08:56
【问题描述】:
我正在尝试创建自定义光标适配器并将其附加到我的列表视图。
虽然我还没有在我的适配器中创建文本框和设置值, 当我尝试调用 super(ctx, c);
时,我的代码当前会引发运行时异常可能出了什么问题?网上搜遍了,没找到。提前致谢!
自定义光标适配器:
public class CustomCursorAdaptor extends CursorAdapter {
private Context context;
private int layout;
public CustomCursorAdaptor (Context ctx, int layout, Cursor c, String[] from, int[] to) {
super(ctx, c);
this.context = ctx;
this.layout = layout;
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return(new View(context));
}
@Override
public void bindView(View v, Context context, Cursor c) {
}
}
和我的活动:
public class DynamicScrollView extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx=getBaseContext();
RelativeLayout newLayout=new RelativeLayout(ctx);
ListView lv=new ListView(ctx);
SQLiteDatabase db;
db = ctx.openOrCreateDatabase("TShow.db", SQLiteDatabase.OPEN_READONLY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
Cursor cur = db.query("control", new String[] {"id"}, "parent_id=2", null, null, null, null);
CustomCursorAdaptor adapter = new CustomCursorAdaptor(ctx, lv.getId(), cur, new String[] {"id"}, new int[] {2});
lv.setAdapter(adapter);
newLayout.addView(lv);
setContentView(newLayout);
}
}
【问题讨论】:
标签: android sqlite android-listview