0

I have a listview with button and text as row elements. I want on scrolling only button should have the focus and not the entire list. But always the entire list has the focus and not the button. Also, if the button has the focus then will the listview onItemSelected method be called ?

Listview in main.xml

<ListView
        android:id="@+id/episodes_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:clickable="true" />

Child items added in row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"    
android:descendantFocusability="afterDescendants" >

<TextView
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:ellipsize="end"
    android:focusable="true"
    android:gravity="left|center"
    android:singleLine="true"
    android:textColor="#000000"
    android:textStyle="bold" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/selector_btn_popup_play"
    android:gravity="center"
    android:text="@string/play"
    android:textColor="@drawable/selector_btn_text_color_light" />

    </LinearLayout>
thefrugaldev
  • 1,619
  • 4
  • 18
  • 36

2 Answers2

0

Try setting ListView not clickable

<ListView
    android:id="@+id/episodes_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:choiceMode="singleChoice"
    android:clickable="false" />

And add tag yourButton.setTag() to button in your ListView's getView() method to refer to current cell and add OnClickListener to button. In onClick() handle item click by getting tag from button.

EDIT

If listview is still clcickable, check accepted answer here

Community
  • 1
  • 1
Heisenberg
  • 3,153
  • 3
  • 27
  • 55
0

Set item ListView not clicable possible in the adapter using this line in the method getView: rowView = inflater.inflate(R.layout.menu_item, null); rowView.setOnClickListener(null);

Mykhailo
  • 331
  • 3
  • 18