ListView в TabLayout не работает - PullRequest
0 голосов
/ 15 марта 2011

Привет, я не могу получить представление списка, работающее в макете моей вкладки. Он продолжает сбой в 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> -->

1 Ответ

1 голос
/ 15 марта 2011

Вы не поместили ListView во вкладку.Тот факт, что он является потомком FrameLayout, автоматически не устанавливает для него вкладку. Вот пример проекта , демонстрирующий, как взять детей из FrameLayout и добавить их в качестве вкладок в TabHost.

...