在Android中我要在Tab中掉用List
(这里面要求:list和Tab用同一个Activity)
哪位高手给个方案?

解决方案 »

  1.   

    Activity:
     TabHost tabhost = getTabHost();
            LayoutInflater.from(this).inflate(R.layout.listview, tabhost.getTabContentView(), true);
            tabhost.addTab(tabhost.newTabSpec("tab1").
             setIndicator("手机").setContent(R.id.phone));
    //R.id.phone是在layout中的包含list区域的layout 的id
          
            phoneListView = (ListView)findViewById(R.id.phoneList); 
    //R.id.phonelist是在layout中的包含listView 的id
            ArrayAdapter<String> adapterPhone = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, data);
            phoneListView.setAdapter(adapterPhone);xml:
    <FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <LinearLayout android:id="@+id/phone"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
      <ListView android:id="@+id/phoneList" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
      />
      <TextView android:id="@+id/phone_empty"
        android:background="@drawable/sample_0"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="No files found!"/>
     </LinearLayout> 
      <LinearLayout android:id="@+id/sdcard"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
      <ListView android:id="@+id/sdcardList" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
      />
      <TextView android:id="@+id/sdcard_empty"
        android:background="@drawable/sample_0"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="No files found!"/>
     </LinearLayout> 
    </FrameLayout>
    FrameLayout的目地是将下面的两个区与实现重叠显示
    看代码吧.
      

  2.   


    谢谢,list的使用我还有很多东西要学啊.呵呵!
      

  3.   

    public class demo extends TabActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); final TabHost tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("tab1")
    .setIndicator("demo1")
    .setContent(new Intent(this, demo1Activity.class)));
    tabHost.addTab(tabHost.newTabSpec("tab2")
    .setIndicator("demo2")
    .setContent(new Intent(this, demo2Activity.class))); }
    }demo1Activity与demo2Activity是两个activity,你在它们里面用列表用啥ui组件都行。
    tab中的每项项页面上都是一个activity,至于楼主说的要“list和Tab用同一个Activity”不太明白楼主要表达什么意思
      

  4.   

    就是不用你说的这个方式,setContent(new Intent(this, demo2Activity.class)));
    demo2Activity不就是你为了显示list重新定义的一个activity吗?
      

  5.   

    public List<? extends Map <String,?>> generateDataList();
    谁能帮忙解释下这句代码的意思,尤其是List<? extends Map <String,?>> 是什么类型啊?
    List<? extends Map <String,?>> 是什么类型啊?