2

I'm trying to implement a function that when a TextView contains too many lines of text, it can be collapsed into 2 lines after a user taps a button. It is expected that when the user taps that button again, the TextView should then show the full text it contains. In the collapseView() method, I use setEllipsize as below:

private void collapseView() {
        m_vwText.setMaxLines(2);
        m_vwText.setEllipsize(TruncateAt.END);
        m_vwExpandButton.setText(EXPAND);
    } 

So I wonder what should I do in my expandView() method to show all lines contained in the TextView. Please help and thanks in advance.

4

1 回答 1

0

一个想法是将原始 TextView 值放入一个临时变量并将其保留在那里,并在customView()方法中使用它。

例如:在onCreate()

String originalText=m_vwText.getText().toString().

然后在你的expandView()工作中originalText

private void expandView(){
   m_vwText.setText(originalText);
}
于 2012-08-03T11:34:26.177 回答