2011-05-26 71 views

回答

0

我已經用我的應用程序做了類似的事情。我瀏覽了Android Developer網站上的ExpandableListView小部件。它似乎沒有任何獲取方法可以讓您比較ExpandableListView中的項目的字符串值。

你需要做的是創建你自己的字符串數組,它包含你想要的字符串值。然後使用ExpandableListView的get方法返回所選項目的位置並將其與您的字符串數組進行比較。

換句話說,get方法將返回值"i"。使用myStringArray[i].equals("This string")來比較字符串值。

+0

這是怎麼給我的視圖對象,我可以操縱? – yellavon 2011-05-27 14:47:33

+0

@yellavon:ExpandedListView有一些您可以使用的「onclick」偵聽器。 [This](http://developer.android.com/reference/android/widget/ExpandableListView.OnChildClickListener.html)可能是你正在尋找的人。您可以將您的代碼放入該偵聽器的'onChildClick'函數中。 – 2011-05-27 15:11:35

0

對於你的Adapter類中的getChildView似乎是一項任務。

我做團體一樣在我ExpandableListView:

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    String groupText = (String) ((Map<String,?>) mGroupData.get(groupPosition)).get(KEY); 
    View v = groupText.startsWith(SEARCH_TERM) ? 
         mInflater.inflate(R.layout.layout_1, null) : mInflater.inflate(R.layout.layout_2, null); 
    TextView tv = (TextView) v.findViewById(R.id.mytext); 
    tv.setText(groupText); 
    return v;  
} 

警告!這個代碼沒有優化,它膨脹了每個項目,這是昂貴的。在我的情況下,我並不擔心,因爲我的ExpandableListView有幾個項目