2014-12-08 34 views
1

我爲我的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(); 
       } 
      }); 
     } 


} 
+0

在適當的通貨膨脹前你在做onCreateView的一些操作嗎?將該代碼移動到onActivityCreated或onViewCreated。 – 2014-12-08 07:28:25

+0

顯示您的Feeds_Listview fragment.class文件 – goonerDroid 2014-12-08 07:32:04

+0

@goonerdroid我已添加代碼..請建議。 – 2014-12-08 07:45:08

回答

0

的問題是,在該片段Home的代碼,您在onCreateView寫道。將您的onCreateView()中的代碼移至onActivityCreated()onViewCreated()。 StackOverlfow上有幾個類似的問題,如here

+0

其實,我沒有得到forcestop,我點擊正常速度的抽屜列表。但如果我點擊列表非常非常快它得到forcestop ...希望這會幫助.. – 2014-12-08 07:40:56

0

嘗試,而不是膨脹的容器,試着用虛增您的視圖,而不容器即

rootView = inflater.inflate(R.layout.feeds_listview_layout,null); 

讓我知道這是否正常工作。

+0

感謝您的建議。但我認爲將我的代碼移動到onActivityCreated()爲我的feed_view() – 2014-12-08 08:30:06

+0

工作哦不,再次forcestop,當我點擊抽屜隨機 – 2014-12-08 08:34:26

+0

您是否通過null參數? – goonerDroid 2014-12-08 08:38:26

相關問題