zyunchen
zyunchen

Reputation: 639

listview, onItemClickListener doesn't work

I have search a lot, my item in the listView is a linearlayout, and I have already add android:descendantFocusability="blocksDescendants", but it doesn't work.

I have also see that ,someone say override getView() in adapter, and add onCLickListener to the view, I don't know it will work or not on earth,but why onItemClickListener can not work.

And setOnItemSelectedListener works well .why?! can not get a clue.

<?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");
                     }
   }
 }

Upvotes: 0

Views: 1540

Answers (1)

zyunchen
zyunchen

Reputation: 639

I have already know how to solve this problem. As I have write the adapter myself.And in the getView() method in adapter. I set the view clickable. which makes this problem. cause that the click action will be first handled by the child view ,when it doesn't handle this action, its parent will handle it later.

Upvotes: 1

Related Questions