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?
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; } });
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.
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.
Just override isEnabled(position) in your adapter and return false
@Override public boolean isEnabled(int position) { return false; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With