How to make a recursive onClickListener for expanding and collapsing?
- by hunterp
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);
}
});
}
};