Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make full row clickable in listview android

Tags:

android

I have a ListView with contents as suppose android in 1st row,blackberry in second row and iphone in 3rd row so on now I want to make ListView's whole row clickable but when I click above content of listview row then it performs only click event but I want if I click any where in a row then a click action should be performed.My code for making listview clickable is below:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listartistspacedetailview);

    setListAdapter(new ArrayAdapter(this,R.layout.listitem_layout,R.id.barrio, keywordxmlparsing.array_artistname));

}   
@Override
protected void onListItemClick(ListView l, View v, int position, long thisID)
{
    Intent i = new Intent(Artistspacedetailview.this, Loadingimagetab.class);
    startActivity(i);   
}

and ListView tag in xml file is :

<ListView
    android:clickable="true"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_below="@id/horizontolline"
    android:cacheColorHint="#00000000"
    android:drawSelectorOnTop="false" />
like image 832
shyam Avatar asked Dec 28 '11 11:12

shyam


2 Answers

I know this question is old, but it was the first hit for me in google when I was looking for this problem.

This is my solution.

<ListView
    android:id="@+id/XXXXXX"
    android:layout_width="fill_parent"   // Changed from wrap content
    android:layout_height="fill_parent"  // Changed from wrap content
    android:clickable="true" >           // This was suggested in other topics
</ListView>
like image 189
TFennis Avatar answered Nov 06 '22 16:11

TFennis


This is old, but to any one else it might help. Set the inflating layout to fill parent and also set to any other item that may be clickable inside the layout to false, such that the list item may get all the focus. Also set the items to focusable false and focusableOnTouch false also.

like image 26
Rat-a-tat-a-tat Ratatouille Avatar answered Nov 06 '22 14:11

Rat-a-tat-a-tat Ratatouille