从另一个调用

问题描述:

一个片段我解释的事情是非常糟糕的,我会尽力做到最好:)从另一个调用

我试图在每个选项卡使用Tabhost和显示列表片段。

[在TabView的ListFragments]:enter image description here

这是它的外观。

点击列表元素,调用另一个片段来显示细节,它显示如下。 [点击列表元素]:enter image description here 有2个问题。

  1. DetailsFragment不是全屏。即能够看到列表(您可以在上图中看到)
  2. 当我回到选项卡视图并单击列表时,它会显示: "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> 

在此先感谢

+1

发布您的代码和logcat以及。 – GrIsHu

+1

如果以下内容不帮助提供代码片段 – FraZer

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)] " 

请致电在UI线程notifyDataSetChanged()yourListView.requestLayout()加入items.The后问题是绑定到Adapter的集合在后台线程中更改。因此,解决方案是将其移动到UI线程(如上所述)或简单地用runOnUiThread()包装它。

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

要调用另一个片段中的电流:

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

编辑:

显示明细片段全屏,请以下更改:

  1. 在你的滚动视图 与android:layout_height="fill_parent"

  2. 更换android:layout_height="wrap_content"在你TableLayout 与android:layout_height="fill_parent"

+0

谢谢您的回复。第一个问题已解决:)但第二个问题是新的片段只有一半的屏幕,即它显示在列表片段的上方。我想要这个片段采取完整的场景 – user1743673

+0

我很高兴你的第一个问题得到解决。 Plz提供相关的xml文件。 –

+0

我发布了xml文件。 – user1743673

对于上面你需要简单地添加你只需要实例的片段:

对于示例 -

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

感谢您的回复。我已经做好了。我现在面临的问题是:单击listFragment时,它不会出现在完整的scree上,它只会出现在屏幕的某个部分。正如我在图2中所示 – user1743673

更换android:layout_height="wrap_content"试试这个例子

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

它真的帮助你用碎片从另一个分段。

使用hadler来通知您的列表,因为您不能从后台或工作线程访问任何UIComponent,所以它必须从UI线程访问。确保使用下面的技巧。

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

@Override 
public void run() { 
    listadapter.notifyDataSetChanged(); 
    } 
});