use*_*673 2 android list tabview android-fragments
我解释的事情非常糟糕,我会努力做到最好:)
我试图使用Tabhost并在每个选项卡中显示列表片段.
[tabview中的ListFragments]:
这是它的外观.
单击列表元素后,将调用另一个片段以显示详细信息,如下所示.[在列表元素上单击]:
有两个问题.
当我回到标签视图并单击列表时,它会显示:
"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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
提前致谢
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)] "
Run Code Online (Sandbox Code Playgroud)
请在添加项目后调用notifyDataSetChanged()并yourListView.requestLayout()在UI线程中.问题是绑定到适配器的集合在后台线程中更改.因此,解决方案是将其移动到UI线程(如上所述)或简单地将其包装runOnUiThread().
runOnUiThread(new Runnable() {
public void run() {
your_collection.add(item);
your_adapter.notifyDataSetChanged();
yourListView.requestLayout();
}
});
Run Code Online (Sandbox Code Playgroud)
要调用当前的另一个片段:
SecondFragment secFrag = new SecondFragment();
FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
fragTransaction.replace(R.id.frame_fragment,secFrag );
fragTransaction.addToBackStack(null);
fragTransaction.commit();
Run Code Online (Sandbox Code Playgroud)
编辑:
要显示详细信息片段全屏,请进行以下更改:
在您的scrollView替换android:layout_height="wrap_content"为android:layout_height="fill_parent"
在你的TableLayout替换android:layout_height="wrap_content"为android:layout_height="fill_parent"
| 归档时间: |
|
| 查看次数: |
20118 次 |
| 最近记录: |