2013-04-23 68 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函数