开发者

Untouchable ListView within tabhost

开发者 https://www.devze.com 2023-02-07 19:48 出处:网络
I\'ve been agonising for a while now about something which ought to be relatively simple, but I can\'t seem to get it to work. The data for each ListView is displaying correctly, and I can select and

I've been agonising for a while now about something which ought to be relatively simple, but I can't seem to get it to work. The data for each ListView is displaying correctly, and I can select and activate the onItemClickListener by using the trackball. However, I cannot scroll down or select any of the items by touch, which I know I should be able to. Any help much appreciated. My code开发者_Python百科 and xml follows:

public class POITab extends TabActivity implements AdapterView.OnItemClickListener {

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.poitab);

    ListView raillist=(ListView)findViewById(R.id.raillist);
    Cursor mrailStationsCursor = db.type_query(KEY_RAIL);
    setupTab(raillist, mrailStationsCursor, "Rail", R.drawable.logo);

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i("touched", " yes");
}

public void setupTab (ListView list, Cursor cursor, String tabname, int drawable) {
startManagingCursor(cursor);
String[] from_all = new String[]{DbAdapter.KEY_NAME};
int[] to_all = new int[] {android.R.id.text1};
list.setAdapter(new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1, cursor, from_all, to_all));
list.setOnItemClickListener(this);

TabHost.TabSpec spec= getTabHost().newTabSpec(tabname);
spec.setContent(list.getId());
spec.setIndicator(tabname, getResources().getDrawable(drawable));
getTabHost().addTab(spec);
}
 }

poitab.xml:

<?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">
<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:paddingTop="62px">
<ListView android:id="@+id/raillist"
android:choiceMode="singleChoice"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
</ListView>
</FrameLayout>
</TabHost>`


I've found out what the problem was - I had a ListView declared in the layout (not shown above, perhaps I should have included the whole source) that wasn't being used, and all touch events were being handled by that. So, moral of the story, only have the ListViews that you need within a TabHost, otherwise it will cause you problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消