简体   繁体   中英

How do i to recognize mouse click on item of listview?

I have one problem with listview. I´ll try recognize when i click(with touch) on one item of listview. I tried with setOnItemClickListener, but only work with keyboard.

What can i do? What do bad?

Edit: I use ListActivity. And use onListItemClick, but when i click on AVD with mouse, not work.

Edit 2: I use a custom Listview, that contains a TextView and ImageView

 <LinearLayout android:id="@+id/lista"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ListView android:id="@android:id/list"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="3dp"
        >

    </ListView>   
  </LinearLayout>



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   >

   <TextView android:id="@+id/texto"
       android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:textSize="15dp"
   android:textStyle="bold" 
   android:gravity="left"
   android:padding="5dp"
   android:paddingBottom="5dp"
   android:text="@string/texto"
    />
    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         >
        <ImageView 
           android:id="@+id/btn_imagen"
           android:scaleType="center"
           android:layout_width="match_parent"
           android:layout_height="150dp"
           android:src="@drawable/logo"
           android:contentDescription="@string/Imagen"/>

    </LinearLayout>
</LinearLayout>

Using a ListActivity you can use onListItemClick (ListView l, View v, int position, long id) . This also works using a ListFragment with onListItemClick (ListView l, View v, int position, long id) .

If you have an implementation of ListAdapter (eg CursorAdapter ) you can set your own View.OnClickListener in onBind() to the desired View elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM