ListView in TabLayout not working
Hi I cant seem to get a listview working in my tab layout. It keeps failing at list.setAdapter(mSchedule); This is my code and XML. Thanks for any input
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_p开发者_如何学编程arent"
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> -->
You didn't put the ListView
in a tab. Just because it is a child of the FrameLayout
does not automatically set up a tab for it. Here is a sample project demonstrating how to take children of a FrameLayout
and add them as tabs to the TabHost
.
精彩评论