Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 434
Tizianoreica Avatar asked Jul 30 '13 11:07

Tizianoreica


People also ask

How do you make a view not clickable on android?

To make your relativelayout block touches and clicks for all of its children you simply need to set the onTouchListener, like this: YOUR_RELATIVE_LAYOUT. setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ignore all touch events return true; } });

How do I create a custom list view?

What is custom listview? Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

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.

like image 180
g00dy Avatar answered Oct 09 '22 04:10

g00dy


Just override isEnabled(position) in your adapter and return false

@Override public boolean isEnabled(int position) {     return false; } 
like image 26
Arun C Avatar answered Oct 09 '22 03:10

Arun C