0

嗨,我似乎无法在我的选项卡布局中使用列表视图。它在 list.setAdapter(mSchedule); 处一直失败;这是我的代码和 XML。感谢您的任何意见

   public class ttTuesday extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ListView list = (ListView) findViewById(R.id.LISTVIEW);
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map = new HashMap<String, String>();

    for(int i=0; i<About.timetable.length; i++){

        //check if sorting by category and make sure at least one category is TRUE
        if(About.timetable[i][0].contains("Tuesday")){

                map = new HashMap<String, String>();
                map.put("time", About.timetable[i][1] + "-" + About.timetable[i][2]);
                map.put("location", "\tLocation: " + About.timetable[i][4]);
                map.put("subject","\tSubject: " +  About.timetable[i][3]);
                mylist.add(map);


        }
}
    final SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.timetableday,
            new String[] {"time", "location", "subject"}, new int[] {R.id.TIME, R.id.LOCATION, R.id.SUBJECT});
    list.setAdapter(mSchedule);
    list.setTextFilterEnabled(true);

}

}

   <?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="4dip" android:paddingBottom="6dip"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView android:id="@+id/TIME" android:textSize="24sp"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="Bold" />

    <TextView android:id="@+id/LOCATION" android:textSize="18sp"
        android:layout_width="wrap_content" android:layout_height="fill_parent" />

    <TextView android:id="@+id/SUBJECT" android:textSize="18sp"
        android:layout_width="wrap_content" android:layout_height="fill_parent" />

</LinearLayout>

    <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp">
            <ListView android:id="@+id/LISTVIEW" android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
         </FrameLayout>          
    </LinearLayout>
</TabHost>

<!-- <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<SeekBar
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:id="@+id/seekbar"
   android:progress="50"
   />
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:id="@+id/seekbarvalue"
   android:text="5000"
   />
</LinearLayout> -->
4

1 回答 1

1

你没有把它ListView放在一个标签里。仅仅因为它是的子级FrameLayout不会自动为其设置选项卡。这是一个示例项目,演示如何获取 a 的子级FrameLayout并将它们作为选项卡添加到TabHost.

于 2011-03-15T17:00:57.293 回答