How to make this list non-selectable?

I want to make listview unselectable and unattractive. I am talking about the color change that occurs when I click on a list item. The code is below. I am new to android, so please be kind.

from: listitem.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="8px"> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF"/> <TextView android:id="@+id/data" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16px"/> </LinearLayout> 

from: details.java

 TestActionAdapter() { super(TestDetails.this, R.layout.action_list_item, actions); } @Override public View getView(int position, View convertView, ViewGroup parent) { TestAction action = actions.get(position); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.action_list_item, parent, false); TextView label = (TextView) view.findViewById(R.id.label); label.setText(action.getLabel()); TextView data = (TextView) view.findViewById(R.id.data); data.setText(action.getData()); return view; } 
+7
source share
3 answers

See the answer here:

How to disable list items ...

We basically extend the ArrayAdapter and add these 2 functions:

  @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return false; } 
+16
source

If all you want is to prevent all lines from being highlighted when clicked, just use ListView android:listSelector="@android:color/transparent"

+8
source

When you return the view from the getView(..) method, just set view.setEnabled(false) before the return view .

0
source

All Articles