Context
I have a list view where the row is basically composed of two TextView (a title and a content).
The second TextView can have a long text so I set maxLines="6"
. When user click on the row I get rid of the maxLines
in order 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
Above code works great. I would like to be able to select my second TextView (content) too so I set android:textIsSelectable="true"
(also tried setting programmatically).
But I can't expand/collapse my TextView because onItemClick
is no longer called
That's because textIsSelectable
catches all click event...
From Android doc:
When you call this method to set the value of textIsSelectable, it sets the flags focusable, 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 a state you had set previously, 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 didn't manage to make it work.
So, any ideas how to use both textIsSelectable
and onItemClick
?
PS: Supporting only Android > 4.0.