2011-09-15 67 views
0

我搜索了很多,我在listView中的项目是一个线性布局,我已经添加android:descendantFocusable="blockDescendants",但它不起作用。listview,onItemClickListener不起作用

我也看到,有人说适配器覆盖getView(),并添加onCLickListener的视图,我不知道它会工作或不在地球上,但为什么onItemClickListener无法工作。

和setOnItemSelectedListener运作良好。为什么?!无法获得线索。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/item_style" 
android:focusable="true" 
android:descendantFocusability="blocksDescendants"> 
<ImageView 
    android:id="@+id/dialog_item_type" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:paddingLeft="5dp" 
    android:focusable="false" 
    /> 
<TextView android:layout_weight="1" 
    android:id="@+id/dialog_item_name" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"  
    android:textStyle="bold" 
    android:textColor="#FFFFFFFF" 
    /> 

<ImageView 
    android:id="@+id/dialog_item_sel" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:paddingRight="5dp" 
    /> 

private class FileListView extends ListView{ 
    private List<Map<String, Object>> tempShowList ; 
    public FileListView(Context context) { 
     super(context); 
     this.setSelector(R.drawable.item_unfocus); 
     this.setItemsCanFocus(true); 
     this.setClickable(true); 
     this.setOnItemClickListener(new OnItemClickListener() { 

      public void onItemClick(AdapterView<?> adapterView, View arg1, 
        int position, long arg3) { 
         Log.e("on item click","here"); 
        } 
    } 
} 
+0

您是否在尝试之前尝试过? –

+0

你说android:descendantFocusability = beforeDescendants?还是不设置这个?我试图不设置白蚁徒步。 @Yashwanth库马尔 – zyunchen

+0

我尝试beforeDescendants.in徒然..什么在地球上它得到的问题! – zyunchen

回答

1

我已经知道如何解决这个问题。正如我自己写适配器一样。并且在适配器的getView()方法中。我将视图设置为可点击。这使得这个问题。导致点击操作将首先由子视图处理,当它不处理此操作时,它的父代将在稍后处理它。

相关问题