Call one fragment from another

六眼飞鱼酱① 提交于 2019-12-02 00:33:30
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification.

Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class android.widget.ListView) with Adapter(class android.widget.SimpleAdapter)] "

Please call notifyDataSetChanged() and yourListView.requestLayout() in the UI thread after adding items.The problem is that your collection that bound to Adapter is changed in the Background thread. Hence the solution is moving it to UI thread(as I stated above) or simply wrapping it with runOnUiThread().

runOnUiThread(new Runnable() {
  public void run() {
    your_collection.add(item);
    your_adapter.notifyDataSetChanged();
    yourListView.requestLayout();
  }
});

To call another fragment the current:

SecondFragment secFrag = new SecondFragment();
FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
                    fragTransaction.replace(R.id.frame_fragment,secFrag );
                    fragTransaction.addToBackStack(null);
                    fragTransaction.commit();

EDIT:

To Display Detail fragment full Screen, please make following changes:

  1. In your scrollView Replace android:layout_height="wrap_content" with android:layout_height="fill_parent"

  2. In your TableLayout Replace android:layout_height="wrap_content" with android:layout_height="fill_parent"

For the above You need to simply add a fragment you just need an instance of:

For example-

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Search fragment = new  Search();
fragmentTransaction.add(R.id.mainLayout,fragment , "MY_FRAG");
fragmentTransaction.commit();

Try this example

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Search fragment = new  Search();
    fragmentTransaction.add(R.id.mainLayout,fragment , "MY_FRAG");
    fragmentTransaction.commit();

It really helped you to use fragment from another fragment.

Use hadler to notify your list because you can not access any UIComponents from background or worker thread, so it must be access from UI Thread. To ensure that use following trick.

Handler mHandler = new Handler();
mHandler.post(new Runnable() {

@Override
public void run() {
    listadapter.notifyDataSetChanged();
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!