我爲我的android應用程序使用抽屜列表。 有問題。 當我點擊隨機(非常快),然後我得到forcestop和java.lang.IllegalStateException: Content view not yet created
顯示在日誌。 我米使用片段java.lang.IllegalStateException:使用抽屜時尚未創建的內容視圖
我M還得到以下運行時錯誤 在android.support.v4.app.ListFragment.ensureList(ListFragment.java:32
這裏是在我的代碼一個部分從抽屜表選擇和
Fragment home = new Home();
Fragment feeds = new Feeds_ListView();
.....
private void selectItem(int position)
{
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
switch (position)
{
case 0:
setTitle(title[position]);
ft.replace(R.id.content_frame, feeds);
break;
case 1:
setTitle(title[position]);
ft.replace(R.id.content_frame, NewPostFragment);
break;
case 2:
setTitle(title[position]);
ft.replace(R.id.content_frame, SearchDetailsFragment);
break;
case 3:
setTitle(title[position]);
ft.replace(R.id.content_frame, feeds1);
break;
case 4:
setTitle(title[position]);
ft.replace(R.id.content_frame, UserDetailsFragment);
break;
case 5:
setTitle(title[position]);
ft.replace(R.id.content_frame, FBActivity);
break;
}
ft.commit();
mDrawerList.setItemChecked(position, true);
setTitle(title[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public void setTitle(CharSequence title)
{
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
這裏是Feeds_ListView()的一部分;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
context=container.getContext();
rootView = inflater.inflate(R.layout.feeds_listview_layout, container, false);
list = (ListView) rootView.findViewById(android.R.id.list);
mRelativeLayout=rootView.findViewById(R.id.mRelativeLayout);
saveProgress =(ProgressBar) rootView.findViewById(R.id.loadpost);
saveProgress.setVisibility(View.INVISIBLE);
userAdapter = new CustomListAdapter(getActivity(), R.layout.feeds_listview_item,userArray);
mRelativeLayout.setVisibility(View.GONE);
list.setItemsCanFocus(false);
list.setAdapter(userAdapter);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
SharedPreferences settings =getActivity().getSharedPreferences("newdatabase",0);
String user_id=settings.getString("user_id", "--");
if(user_id.equals("--") || user_id.equals(""))
{ FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, FBActivity);
ft.commit();
}else{
new Onscrollasync().execute();
((PullToRefresh_Master) getListView()).setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
new Onscrollasync().execute();
}
});
}
}
在適當的通貨膨脹前你在做onCreateView的一些操作嗎?將該代碼移動到onActivityCreated或onViewCreated。 – 2014-12-08 07:28:25
顯示您的Feeds_Listview fragment.class文件 – goonerDroid 2014-12-08 07:32:04
@goonerdroid我已添加代碼..請建議。 – 2014-12-08 07:45:08