shyam
shyam

Reputation: 1306

how to make full row clickable in listview 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" />

Upvotes: 5

Views: 5373

Answers (3)

DSS
DSS

Reputation: 7259

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.

Upvotes: 2

TFennis
TFennis

Reputation: 1423

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>

Upvotes: 9

nisha.113a5
nisha.113a5

Reputation: 2024

This might be helpful to you...

listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> list, View view, int position, long id) {
           //code to be executed.
    }

 }
});

Upvotes: -2

Related Questions