[英]ListActivity not showing on screen, can only see a blank white screen
我一定在做一些愚蠢的事情,缺少一些關鍵的部分。 請幫我調試這個看起來很簡單的代碼,以便從數據庫中渲染ListActivity
public class ExAct1 extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//I'm trying to use default view but using my own <ListView> also doesn't work
//setContentView(R.layout.exp_list_act1);
From query = new Select().from(CategoryTable.class); //ActiveAndroid Library
Cursor cursor = Cache.openDatabase().rawQuery(query.toSql(), query.getArguments());
//startManagingCursor(cursor); //commenting or uncommenting has no effect
this.setListAdapter(new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
cursor,
new String[] {"_id"}, //tried other column name from my table - no effect
new int[] {android.R.id.text1},
0));
//these work - just to test Cursor is valid and has data
Log.e(TAG, "Cursor Row Count: " + cursor.getCount()); // 3 rows
Log.e(TAG, "Cursor Col Count: " + cursor.getColumnCount()); // 3 cols
}
}
老實說,這是我的整個課堂代碼。 我可以在屏幕上看到該活動,標題欄中的名稱與該活動在清單中定義的名稱相同-但在標題下方,我只看到空白的空白屏幕。
您需要取消注釋該行
//setContentView(R.layout.exp_list_act1);
並且您的xml布局文件必須包含ID為“ @android:id / list”的listview
ActiveAndroid使用“ Id”作為默認ID列名稱。 可以將其更改為“ _id”,但是如果您不記得這樣做,那么可能是您的問題。
如果是這樣,請嘗試以下方法:
setListAdapter(new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
cursor,
new String[] {"Id"},
new int[] {android.R.id.text1},
0));
另外,您可以像這樣更改CategoryTable類中的id列名稱:
@Table(name = "category", id = BaseColumns._ID)
public class CategoryTable extends Model {...}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.