大佬教程收集整理的这篇文章主要介绍了android – 当我在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中添加一个字母:
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} 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} 03-15 14:07:51.104: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 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} 03-15 14:07:51.119: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 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} 03-15 14:07:51.135: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 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} 03-15 14:07:51.151: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 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} 03-15 14:07:51.205: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 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} 03-15 14:07:51.213: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 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} 03-15 14:07:51.221: D/LIST(4176): getGroupView() groupPosition 1 isExpanded true row android.widget.RelativeLayout{41a17d98 V.E..... ......I. 0,0} 03-15 14:07:51.229: D/LIST(4176): getChildView()
getGroupView()和getChildView()为每个输入的字母调用MULTIPLE次.在上面的例子中,listview显然被重绘了八次(我在该列表的列表中有2个组视图和一个子视图.)
我错过了什么?当我在edittext中输入内容时,甚至不需要重新绘制列表视图.即使重新绘制,为什么有八个调用不同的getview-methods?
编辑:
我现在看到,即使我崩溃和/或扩展了群视图,也会对getgroupview和getchildview-methods进行大量调用.这是怎么回事?
EDIT2:
现在进行了一些测试,在正常活动中使用带有edittext的列表,似乎列表不会经常重新绘制.所以问题似乎在于我在对话中提出这个问题.不知道为什么它甚至需要重新绘制.
但我确实看到了一些可以让它调用超出需要的东西:在你的布局中,你将ExpandableListView高度设置为wrap_content.我认为这不是一件好事:
你让他需要重新绘制它的子,知道它的大小,以便适合它的内容,而它不需要包装它的内容,因为它是一个可滚动的布局.
尝试将其设置为0dip,使用layout_weight =“1”以便为文本视图留出空间:
<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>
以上是大佬教程为你收集整理的android – 当我在EditText中编辑数据时,BaseExpandableListAdapter调用getgroupview()全部内容,希望文章能够帮你解决android – 当我在EditText中编辑数据时,BaseExpandableListAdapter调用getgroupview()所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。