2011-03-15 20 views
0

嗨我似乎无法得到在我的标签布局中工作的列表视图。它在list.setAdapter(mSchedule)处保持失败; 这是我的代码和XML。感谢您的任何输入TabLayout中的ListView不起作用

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> --> 
+0

http://joshclemm.com/blog/?p=59这可能会有所帮助。 – 2011-03-15 16:59:49

回答

1

你没有把ListView的标签。仅仅因为它是FrameLayout的孩子,不会自动为它设置一个标签。 Here is a sample project演示如何带着FrameLayout的孩子,并将它们作为标签添加到TabHost