Context
I have a list view in which a string basically consists of two TextViews (title and content).
The second TextView may have long text, so I set maxLines="6" . When the user clicks on the line , I get rid of maxLines to show the full text.
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { TextView content = (TextView ) view.findViewById(R.id.content); int limit = getResources().getInteger(R.integer.default_max_lines); if (content.getMaxLines() > limit) { content.setMaxLines(limit); } else { content.setMaxLines(Integer.MAX_VALUE); } }
Problem
It works fine on code. I would also like to be able to select the second TextView (content) to set android:textIsSelectable="true" (also tried setting it programmatically).
But I can not expand / collapse my TextView because onItemClick no longer called
This is because textIsSelectable catches all click events ... From Android doc:
When you call this method to set the value of textIsSelectable, it sets the flags with focus, focusableInTouchMode, clickable, and longClickable to the same value. These flags correspond to the attributes android: focusable, android: focusableInTouchMode, android: clickable and android: longClickable. To restore any of these flags to the state you set earlier, call one or more of the following methods: setFocusable (), setFocusableInTouchMode (), setClickable (), or setLongClickable ().
I tried to set these flags to false after setTextIsSelectable(true) , but I was not able to get it to work.
So, any ideas how to use both textIsSelectable and onItemClick ?
PS: Support only Android> 4.0.