How to make a recursive onClickListener for expanding and collapsing?
Posted
by
hunterp
on Stack Overflow
See other posts from Stack Overflow
or by hunterp
Published on 2011-01-12T19:45:38Z
Indexed on
2011/01/12
19:53 UTC
Read the original article
Hit count: 156
In plain english, I have a textview, and when I click on it I want it to expand, and when I click on it again, I want it to compress. How can I do this? I've tried the below, but it warns on the final line about expander might not be initialized on holderFinal.text.setOnClickListener(expander);
So now the code:
final View.OnClickListener expander = new View.OnClickListener() {
@Override
public void onClick(View v) {
holderFinal.text.setText(textData);
holderFinal.text.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
holderFinal.text.setText(shortText);
holderFinal.text.setOnClickListener(expander);
}
});
}
};
© Stack Overflow or respective owner