BaseExpandableListAdapter calls getgroupview () when I edit data in an EditText

I am working with ExpandableListView in Android.

I have a dialogue that inflates this view:

<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> 

My BaseExpandableListAdapter looks like this for the getgroupview () method:

  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; } 

To my problem:

when i write stuff in my edittext getgroupview calls all the time! This is the result from the log for adding only one letter to the edittext:

 03-15 14:07:51.072: D/LIST(4176): getGroupView() groupPosition 0 isExpanded false row android.widget.RelativeLayout{41a17d98 VE.... ......I. 0,0-0,0} 03-15 14:07:51.080: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.104: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.119: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.135: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.151: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.205: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.213: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......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 VE.... ......I. 0,0-0,0} 03-15 14:07:51.221: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 VE.... ......I. 0,0-0,0} 03-15 14:07:51.229: D/LIST(4176): getChildView() 

getGroupView () and getChildView () are called MULTIPLE times for each letter entered. In the above example, the list appears to be redrawn eight times (I have 2 group views and one child view in the list for this example.)

What am I missing? The list of lists does not even need to be redrawn when I type in my edittext. And even if it redraws, why are there eight calls to various getview methods?

EDIT: Now I see that even when I collapse and / or expand group views, there are PLENTY calls to the getgroupview and getchildview methods. Is that how it should be?

EDIT2: Was there some testing now using a list with edittext in normal activity, and it seems that the list does not redraw so often. So the problem is that I present this in a dialog box. I can’t understand why it is even necessary to redraw it, though.

+4
source share
1 answer

You can never tell when the getView methods will be called (also true for getGroupView ) and how many times.

but I see something that can cause it to call more than necessary: ​​in your layout, you set the height of the ExpandableListView wrap_content . I do not think this is good:

you make him redraw his child to find out the size he orders to fit his content, while he does not need to wrap his contents with a scrollable layout.

Try setting 0dip instead of 0dip with layout_weight="1" to layout_weight="1" space for your text view:

 <ExpandableListView android:id="@+id/comments_list" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" android:layout_above="@+id/editTextNewComment" android:layout_alignParentLeft="true" > </ExpandableListView> 
+7
source

Source: https://habr.com/ru/post/1469511/


All Articles