2011-01-31 48 views
0

我一直在痛苦一段時間,應該是相對簡單的東西,但我似乎無法得到它的工作。每個ListView的數據都正確顯示,我可以使用軌跡球選擇並激活onItemClickListener。但是,我不能通過觸摸向下滾動或選擇任何項目,我知道我應該可以。任何幫助非常感謝。我的代碼和XML如下:tabhost內的不可觸摸的ListView

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

給出了一些進一步的想法,我發現我可以滾動和選擇使用觸摸,但只能在模擬器和手機的屏幕底部。難道是框架佈局在某種程度上覆蓋了ListView? – 2011-01-31 19:30:07

回答

0

我發現了什麼問題了 - 我在佈局(聲明一個ListView上面沒有顯示,也許我應該已經包括了整個來源)沒有被使用,所有觸摸事件正在處理。所以,故事的道德,只有在TabHost中需要的ListViews,否則會導致你的問題。

+0

不幸的是,我有同樣的問題,但我沒有在我的佈局中的另一個ListView ... – 2013-07-22 14:51:26