android非法状态异常内容视图尚未创建? [英] android Illegal state exception content view not yet create?
本文介绍了android非法状态异常内容视图尚未创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我启动我的抽屉活动片段时,非法状态异常内容视图尚未创建错误弹出.这是我的代码和错误.我正在使用自定义列表适配器.
Hi when I start my drawer activity fragment, the illegal state exception content view not yet create error pop up. here is my code and error. I am using an custom list adapter.
错误:
10-14 09:40:25.926: E/AndroidRuntime(6736): java.lang.IllegalStateException: Content view not yet created
10-14 09:40:25.926: E/AndroidRuntime(6736): at android.app.ListFragment.ensureList(ListFragment.java:386)
10-14 09:40:25.926: E/AndroidRuntime(6736): at android.app.ListFragment.getListView(ListFragment.java:280)
10-14 09:40:25.926: E/AndroidRuntime(6736): at com.example.fragments.HomeFragment$1.done(HomeFragment.java:74)
我的 oncreateview
my oncreateview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(
R.layout.fragment_home, container, false);
listview=(ListView) rootView.findViewById(android.R.id.list);
return rootView;
}
在 onResume 中调用 mysetlist 适配器
mysetlist adapter call in onResume
@Override
public void onResume() {
super.onResume();
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Shopinfo");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> Shopinfo, ParseException e) {
// TODO Auto-generated method stub
if(e==null){
mShop=Shopinfo;
String[] spots = new String[mShop.size()];
int i = 0;
for(ParseObject Shopinfos : mShop) {
spots[i] = Shopinfos.getString(ParseConstants.KEY_SHOP_NAME);
i++;
}
if (getListView().getAdapter() == null) {
adapter=new ShopListAdapter(list.getContext(), mShop);
setListAdapter(adapter);
}
else {
((ShopListAdapter)getListView().getAdapter()).refill(mShop);
}
}
}
});
}
推荐答案
将以下内容移到 onActivityCreated()
方法或 onViewCreated()
中.
Move the following to onActivityCreated()
method or in onViewCreated()
.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Shopinfo");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> Shopinfo, ParseException e) {
// TODO Auto-generated method stub
if(e==null){
mShop=Shopinfo;
String[] spots = new String[mShop.size()];
int i = 0;
for(ParseObject Shopinfos : mShop) {
spots[i] = Shopinfos.getString(ParseConstants.KEY_SHOP_NAME);
i++;
}
if (getListView().getAdapter() == null) {
adapter=new ShopListAdapter(list.getContext(), mShop);
setListAdapter(adapter);
}
else {
((ShopListAdapter)getListView().getAdapter()).refill(mShop);
}
}
}
});
}
一个好的做法是将所有使用 UI 小部件的东西都放在 onActivityCreated()
方法中.
A good practice is to put everything that uses UI widgets inside onActivityCreated()
method.
这篇关于android非法状态异常内容视图尚未创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文