我正在使用Android中的ExpandableListView。當我編輯EditText中的數據時,BaseExpandableListAdapter調用getgroupview()
我有膨脹這一觀點的對話:
<ExpandableListView
android:id="@+id/comments_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/editTextNewComment"
android:layout_alignParentLeft="true" >
</ExpandableListView>
<EditText
android:id="@+id/editTextNewComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/imageButtonPostNewComment"
android:ems="10"
android:singleLine="true" >
<requestFocus />
</EditText>
我BaseExpandableListAdapter看起來像這樣的getgroupview() - 方法:
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
Log.d("LIST", "getGroupView() groupPosition " + groupPosition + " isExpanded " + isExpanded + " row " + row);
if(row==null) {
LayoutInflater infl = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = infl.inflate(R.layout.list_item_comment,parent,false);
holder = new ViewHolder(row);
holder.imbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Integer pos = (Integer) v.getTag();
//Do something
}
});
row.setTag(holder);
}
else {
holder = (ViewHolder) row.getTag();
}
holder.imbutton.setTag(Integer.valueOf(groupPosition));
holder.header.setText(""+ (groupPosition+1) + " - " + comments[groupPosition].getOwner());
//.... etc - setting all the textviews accordingly
return row;
}
我的問題:
當我在我的edittext中寫入東西,getgroupview一直都會被調用!這是從日誌輸出只是在EditText上增加1個字母:
03-15 14:07:51.072: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.080: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.088: D/LIST(4176): getChildView()
03-15 14:07:51.096: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.104: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.111: D/LIST(4176): getChildView()
03-15 14:07:51.119: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.119: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.127: D/LIST(4176): getChildView()
03-15 14:07:51.135: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.135: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.143: D/LIST(4176): getChildView()
03-15 14:07:51.151: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.151: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.158: D/LIST(4176): getChildView()
03-15 14:07:51.205: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.205: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.213: D/LIST(4176): getChildView()
03-15 14:07:51.213: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.213: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.221: D/LIST(4176): getChildView()
03-15 14:07:51.221: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.221: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0-0,0}
03-15 14:07:51.229: D/LIST(4176): getChildView()
getGroupView()和getChildView()被調用多次對輸入的每個字母。在上面的例子中,listview顯然被重繪了八次(在這個例子中,我有兩個組視圖和一個子視圖)。
我錯過了什麼?當我在我的edittext中鍵入東西時,甚至不需要重繪列表視圖。即使它正在重繪,爲什麼有八個調用不同的getview方法?
編輯: 我現在看到,即使我摺疊和/或擴大groupviews,有調用getgroupview和getchildview方法的PLENTY。這是應該如何?
EDIT2: 現在在正常的活動中使用帶有edittext的列表進行了一些測試,並且似乎列表不會像頻繁那樣重繪。所以這個問題似乎是因爲我在對話中提出這個問題。不明白爲什麼它甚至需要重新繪製。
[ExpandableList getChildView每名兒童的兩倍運行]的可能重複(http://stackoverflow.com/questions/6557240/expandablelist-getchildview-running-per-child) – 2015-01-21 07:50:18