我有两个班,第一堂班很好。我运行了一些测试,看看是否正确访问了数据库。
此代码返回正确的列
> System.out.println(cursor.getColumnCount());
MyAdapter adapter = new MyAdapter(this,R.layout.row,cursor,from,to);
listContent.setAdapter(adapter);
06-13 16:39:56.975: D/dalvikvm(547): GC_CONCURRENT freed 1K, 3% free 9587K/9863K, paused 4ms+2ms
06-13 16:39:57.015: D/dalvikvm(547): GC_FOR_ALLOC freed 0K, 3% free 9587K/9863K, paused 34ms
06-13 16:39:57.025: I/dalvikvm-heap(547): Grow heap (frag case) to 10.481MB for 1102516-byte allocation
06-13 16:39:57.065: D/dalvikvm(547): GC_FOR_ALLOC freed 0K, 3% free 10664K/10951K, paused 29ms
06-13 16:39:57.175: D/dalvikvm(547): GC_FOR_ALLOC freed 596K, 7% free 10532K/11271K, paused 35ms
06-13 16:39:57.275: D/dalvikvm(547): GC_CONCURRENT freed 89K, 3% free 10947K/11271K, paused 3ms+3ms
06-13 16:39:57.315: D/dalvikvm(547): GC_FOR_ALLOC freed <1K, 3% free 10946K/11271K, paused 36ms
06-13 16:39:57.315: I/dalvikvm-heap(547): Grow heap (frag case) to 11.395MB for 669076-byte allocation
06-13 16:39:57.355: D/dalvikvm(547): GC_FOR_ALLOC freed 0K, 4% free 11600K/11975K, paused 34ms
06-13 16:39:57.365: I/dalvikvm(547): threadid=3: reacting to signal 3
06-13 16:39:57.375: I/dalvikvm(547): Wrote stack traces to '/data/anr/traces.txt'
06-13 16:39:57.435: E/(547): Whatis the first value for the timer varfalse
06-13 16:39:57.515: D/gralloc_goldfish(547): Emulator without GPU emulation detected.
06-13 16:40:25.955: E/(547): Whatis the first value for the timer inside the basic buttonfalse
06-13 16:40:25.965: E/(547): Whatis the value of timerstart inside the intentcalls methodfalse
06-13 16:40:26.106: E/(547): Log de error
06-13 16:40:26.106: E/(547): possAnsOne
06-13 16:40:26.106: E/(547): realQ
06-13 16:40:26.106: I/System.out(547): 7
06-13 16:40:26.115: I/System.out(547): android.database.sqlite.SQLiteCursor@41578d88
06-13 16:40:26.125: I/System.out(547): please get this working
06-13 16:40:26.505: I/dalvikvm(547): threadid=3: reacting to signal 3
06-13 16:40:26.515: I/dalvikvm(547): Wrote stack traces to '/data/anr/traces.txt'
我的`MyAdapter类的构造函数被调用,但由于某种原因,不调用public void bindView(View v,Context context,Cursor c)方法
public MyAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
this.context = context;
this.layout = layout;
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View v, Context context, Cursor c) {
// do your magic inhere :) the cursor will be at the correct row position
System.out.println("please select a cursor");
// int nameCol = c.getColumnIndex(People.NAME);
// ListView listContent = (ListView)findViewById(R.id.contentlist);
// ImageView imageView = (ImageView)findViewById(R.id.ImageView01);
int nameCol = c.getColumnIndex(DBAdapter.question);
int realanswer = c.getColumnIndex(DBAdapter.realQuestion);
int firstquest = c.getColumnIndex(DBAdapter.possibleAnsOne);
int useranswer = c.getColumnIndex(DBAdapter.userR);
// TextView label = (TextView) v.findViewById(R.id.TextView01);
// label.setText(nameCol);
System.out.println("What is the column index" +nameCol);
String name = c.getString(nameCol);
String answer = c.getString(realanswer);
String firstnas = c.getString(firstquest);
String userreal = c.getString(useranswer);
// Log.e(LOGS, realanswer);
Log.e(LOGS, "What is the user value" + userreal);// correct
Log.e(LOGS, "What is real value" + answer); // wrong
System.out.println(answer);
System.out.println(userreal);
TextView name_text = (TextView) v.findViewById(R.id.question);
TextView myanswertext = (TextView) v.findViewById(R.id.TextView01);
TextView correctanswer = (TextView) v.findViewById(R.id.TextView02);
ImageView imageView = (ImageView) v.findViewById(R.id.ImageView01);
ImageView imageView2 = (ImageView) v.findViewById(R.id.ImageView02);
if (name_text != null) {
correctanswer.setText(answer);
}
}