1

I m using drawer list for my android application. Got a issue. When I click randomly (very fast) then I get forcestop and java.lang.IllegalStateException: Content view not yet created showing in Log. I m using fragments

I m also getting the following Runtime error at android.support.v4.app.ListFragment.ensureList(ListFragment.java:32

Here is a part of my code in selecting from drawer list and

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);
}

Here is the part of 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();
                }
            });
        }


}
Jesmeen Hoque
  • 411
  • 4
  • 8

2 Answers2

0

The problem is with the code in the Fragment Home that you wrote in the onCreateView. Move the code in your onCreateView() to either onActivityCreated() or onViewCreated(). There are several similar question on StackOverlfow like here.

Community
  • 1
  • 1
Antrromet
  • 15,294
  • 10
  • 60
  • 75
  • Actually, i m not getting forcestop which i m clicking the drawer list in normal speed. but if i click the lists very very fast it gets forcestop... Hopefully this will help.. – Jesmeen Hoque Dec 08 '14 at 07:40
0

Try this instead of inflating a container,try to inflate your view without the container ie

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

Let me know if this works.

williamj949
  • 11,166
  • 8
  • 37
  • 51