How to make the items in a list view not click able. i got topics and items in a list view but the view is same for both topics and items. the items are click able but the topic is not click able. how to achieve this
the list will look like
Topic
item
Topic
item
item
topic. click able(false) did not work, please help
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; } });
OnItemClickListener MshowforItem = new AdapterView. OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((TextView)view). setText("Hello"); } };
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. In the above activity_main.
Don't know if you still need it, but you can implement your own Adapter and override the method isEnabled(int position). Depending on the ViewType of the item you will return true or false.
Sharing my experience, the following did the trick (view refers to the list item view):
view.setEnabled(false); view.setOnClickListener(null);
To make the items in a list non-clickable, you have to make the adapter return false on its isEnabled
method for the items in the list. An easy way to instantiate an adapter and override isEnabled
can be done in the following way:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, from, to, 0) {
@Override
public boolean isEnabled(int position) {
return false;
}
};
This is the correct answer:
I've found a lot of comments saying that
setEnabled(false)
setClickable(false)
setFocusable(false)
would work, but the answer is NO
The only workaround for this approach is doing:
view = inflater.inflate(R.layout.row_storage_divider, parent, false);
view.setOnClickListener(null);
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