Question

I'm very bad in explaining things, i'll try to do my best :)

I was trying to use a Tabhost and display list fragments in each tab.

[ListFragments in tabview]:enter image description here

This is how it looks.

On click on the list element, another fragment is invoked to display the details, it's displaying as below. [Onclick on the list elements]:enter image description here There are 2 problems.

  1. The DetailsFragment is not full screen. i.e. an able to see the list(u can see in the above image)
  2. When i go back to the tab view and click on the list it says : "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)] " TabView xml:

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:orientation="horizontal" />
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0" />
    
            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
        </LinearLayout>
    </TabHost>
    

detailsFragment xml :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:shrinkColumns="*"
            android:stretchColumns="*" >

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="50dip"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Msg Id"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv1"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="PID"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv2"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Sender BS"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv3"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Sender NS"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv4"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Sender Interface"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv5"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Receiver BS"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv6"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Receiver NS"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv7"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Receiver Interface"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv8"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Msg Type"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv9"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Msg State"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv10"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Exe Time"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv11"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Init Time"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv12"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Send Time"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv13"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Admin User"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv14"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:text="Payload"
                    android:textColor="#000000"
                    android:textSize="13sp" />

                <TextView
                    android:id="@+id/tv15"
                    android:layout_weight="1"
                    android:background="#a09f9f"
                    android:gravity="center"
                    android:paddingBottom="5sp"
                    android:paddingTop="5sp"
                    android:textColor="#000000"
                    android:textSize="13sp" />
            </TableRow>
        </TableLayout>
    </ScrollView>

</FrameLayout>

Thanks in advance

Was it helpful?

Solution

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"

OTHER TIPS

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();
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top