2013-04-23 31 views
2

我有一個tabhost,Android其它活動點擊返回鍵列表視圖,列表視圖項不能在標籤

的標籤A將連接一個活動,

的一個活動的佈局有一個EDITTEXT下點擊,按鈕和一個列表視圖。

listview是從baseadapter定製的。 listview包含一個textview,沒有按鈕或圖像..等。

當我進入程序,列表視圖產品可以點擊,

它將連接乙子活動。

但是當我點擊返回鍵,(去回活動)

ListView的項目是不行的,它必須向上拖動或向下拖動,

該項目將成爲點擊正確的。

我有搜索一些文學作品。

我曾試圖在我的列表視圖,或LinearLayout中添加TextView的

android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:clickable="false" 

    or 

    descendantFocusability="blocksDescendants" 

但問題是存在的。

如何解決問題?非常感謝你。

我的佈局低於:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/bgColor" 
     tools:context=".MainActivity" > 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="70dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:gravity="center" 
      android:orientation="horizontal" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:layout_marginTop="4dp" 
       android:layout_weight="1" 
       android:gravity="center" > 

       <EditText 
        android:id="@+id/drugText" 
        android:layout_width="224dp" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:ems="10" 
        android:gravity="center_vertical|center" 
        android:hint="@string/searchHint1" 
        android:textSize="18sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:layout_weight="3" 
       android:gravity="left" > 

       <Button 
        android:id="@+id/query" 
        style="@style/ButtonText" 
        android:layout_width="70dp" 
        android:layout_height="48dp" 
        android:layout_gravity="center" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/blue_btn" 
        android:text="@string/search" 
        android:textSize="20sp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/linearLayout1" > 

      <ListView 
       android:id="@+id/drugList" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:clickable="true" /> 
     </LinearLayout> 

    </RelativeLayout> 

我的列表視圖項佈局如下:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/color_listview_border" 
      android:gravity="center" 
      android:minHeight="60dp" > 

      <TextView 
       android:id="@+id/drugNameTV" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="TextView" 
       android:textSize="20sp" /> 
     </LinearLayout> 

    </LinearLayout> 
+0

只是把你的listview的點擊事件在onResume方法,它應該工作,讓我知道你得到了什麼結果 – Aamirkhan 2013-04-23 09:05:46

+0

我已經在onResume()放置listview的點擊事件; \t'@Override \t protected void onResume(){ \t \t super.onResume(); \t \t Log.e(「log」,「on resume」); \t \t drugLV.setOnItemClickListener(新AdapterView.OnItemClickListener(){ \t \t \t公共無效onItemClick(適配器視圖爲arg0, \t \t \t \t \t查看ARG1,ARG2 INT,長\t ARG3){....... (錯誤是這麼長,我在這裏打印照片) [鏈接](http://134.208.3.130/~dickfala/android/err.png) 謝謝非常。 我有使用ActivityGroup控制回來。 我的活動組代碼在這裏[鏈接](http://134.208.3.130/~dickfala/android/ActivityGroup1.java) – dickfala 2013-04-24 01:14:43

+0

我把我的主代碼框架放在這裏[link](http://134.208.3.130/~dickfala /android/DrugQuery.java) 非常感謝。 – dickfala 2013-04-24 01:26:11

回答

0

當你去到B子活動,您可以存儲列表視圖狀態。 回到A subActivity後,您需要恢復列表視圖狀態。

+0

當我回來時,A subActivity在列表中有數據,但它不能單擊該項目。它必須拖動或放下,該項目變成點擊。 – dickfala 2013-04-23 09:00:28

+0

您單擊後退鍵,subActivity不會自動獲得焦點。請嘗試將焦點置於活動或列表視圖上。 – 2013-04-23 09:19:37

+0

如何自動獲得焦點? – dickfala 2013-04-23 09:21:59

0

只是調用adapter.notifyDataSetChanged();在onResume函數