2013-05-15 32 views
0

是否有擴展列表的組TextView的多行文本,然後擴展列表問題:設置組的TextView的MaXLine和擴大名單同時

我想是 - :當第一個列表載入,然後只每行出現一行,當用戶點擊組時,組中的所有行應該可見+組應該同時展開。

我試圖實現說,但是當我在名單上的組視圖中單擊,它得到了擴展,但在組中的所有文本行是不可見的,但是當我再次在同一組中,單擊,所有的線條都可見。

這是什麼,我都試過:

在組getview方法我已經設置的TextView的最大行1

public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { 
      TextView textView = new TextView(CorrectqaFragment.this.getActivity()); 
      textView.setText(getGroup(i).toString()); 

      textView.setMaxLines(1); //set maximum lines of textview to 1. 
       return textView; 
     } 

elv- refrence來擴展列表。

elv.setOnGroupClickListener(new OnGroupClickListener() { 

      public boolean onGroupClick(ExpandableListView parent, View v, 
        int groupPosition, long id) { 

       TextView tv = (TextView)v; 
       tv.setMaxLines(Integer.MAX_VALUE); //set the max lines to max value 

       parent.expandGroup(groupPosition); //expand the group 

       return true; 


      } 
     }); 

回答

0

是的,我試過了,最後得到了答案。實際上問題在於,每當您在可展開列表視圖中展開組時,每次調用getGroupView方法時,我都會設置maxline 1,這就是爲什麼第一次單擊所有組文本行都不可見的原因。

所以這裏是解決方案,爲我工作。

public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { 
     TextView textView = new TextView(CorrectqaFragment.this.getActivity()); 
     textView.setText(getGroup(i).toString()); 

     if (b) { 
      textView.setMaxLines(Integer.MAX_VALUE); 
       }else{ 
      textView.setMaxLines(1); //set maximum lines of textview to 1. 
       } 
      return textView; 
    } 

OnGroupClickListener-:

elv.setOnGroupClickListener(new OnGroupClickListener() { 

     public boolean onGroupClick(ExpandableListView parent, View v, 
       int groupPosition, long id) { 

      parent.expandGroup(groupPosition); //expand the group 

      return true; 


     } 
    }); 

說明: - 檢查組在getGroupView方法擴增或不併設置MAXLINE相應的TextView爲:

  if (b) { 
      textView.setMaxLines(Integer.MAX_VALUE); 
       }else{ 
      textView.setMaxLines(1); //set maximum lines of textview to 1. 
       } 

是布爾返回b其中通過isGroupExpand。 b = true - >組反之亦然。

並從偵聽器中刪除那些正在設置textview max行的行。