Antonio Calì Antonio Calì - 5 months ago 16
Android Question

How set ListView not clickable

I have this

ListView
that just needs to show data.

So I don't want to make it clickable.

First I've tried changing XML listview to:

<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="false" >


But it didn't work.

So to solve my problem I set through code:

list.setSelector(android.R.color.transparent);


but I can't believe there's no better solution. Any idea?

Answer

Here it is, following the comment:

One way to do so is: ListView.setOnClickListener(null); OR

You can add android:focusable="false" android:focusableInTouchMode="false" OR

another way in the layout android:listSelector="@android:color/transparent"

Cheers.