这是在数据库 fragment 上填充 ListView :
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
LinearLayout Layout5 = (LinearLayout) inflater.inflate(R.layout.tab_frag5_layout, container, false);
Cursor allBands;
MyDatabase db;
Context ctx = (Context)TabFragment5.this.getActivity();
db = new MyDatabase(ctx);
allBands = db.getBands();
ListAdapter adapter = new SimpleCursorAdapter (ctx,
R.layout.listelement,
allBands,
new String[] {"BandName"},
new int[] {R.id.text15});
getListView().setAdapter(adapter);
return Layout5;
}
为什么这会在 logcat 上给我“尚未创建内容 View ”? fragment 打开时程序强制关闭...
最佳答案
我通过将适配器和 getListview 移动到 onActivityCreated(...) 来解决它。
onCreateView 只是膨胀并返回布局。
关于Android - 为什么这告诉我 "Content view not yet created"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9286391/