Android - 为什么这告诉我“尚未创建内容视图"? [英] Android - why is this telling me "Content view not yet created"?
本文介绍了Android - 为什么这告诉我“尚未创建内容视图"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是在数据库中的片段上填充列表视图:
This is a populating a listview on a fragment from a database:
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 上显示尚未创建内容视图"?当片段打开时程序强制关闭...
Why is this giving me the "Content view not yet created" On logcat? the program forces close when the fragment opens...
推荐答案
我通过将适配器和 getListview 移动到 onActivityCreated(...) 解决了这个问题.
I solved it by moving the adapter and the getListview to onActivityCreated(...).
onCreateView 只是膨胀并返回布局.
onCreateView just inflates and returns the layout.
这篇关于Android - 为什么这告诉我“尚未创建内容视图"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文