gpt4 book ai didi

android - 当我在 EditText 中编辑数据时,BaseExpandableListAdapter 调用 getgroupview()

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:30:29 25 4
gpt4 key购买 nike

我在 Android 中使用 ExpandableListView。

我有一个对话框使这个 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>

对于 getgroupview() 方法,我的 BaseExpandableListAdapter 看起来像这样:

    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 总是被调用!这是日志的输出,仅在编辑文本中添加一个字母:

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 显然被重绘了八次(我在该示例的列表中有 2 个组 View 和一个 subview 。)

我错过了什么?当我在编辑文本中输入内容时,甚至不需要重新绘制 ListView 。即使正在重绘,为什么会有八次调用不同的 getview 方法?

编辑:我现在看到,即使当我折叠和/或展开组 View 时,也有大量调用 getgroupview 和 getchildview 方法。这是应该的样子吗?

编辑2:现在在正常 Activity 中使用带有 edittext 的列表进行了一些测试,看起来列表没有那么频繁地重新绘制。所以问题似乎在于我在对话框中展示了这个。不明白为什么它甚至需要重新绘制。

最佳答案

您永远无法知道何时调用 getView 方法(对于 getGroupView 也是如此)以及调用了多少次。

但我确实看到了一些可以使其调用超出需要的东西:在您的布局中,您将 ExpandableListView 高度设置为 wrap_content。我不认为这是一件好事:

你让他需要重新绘制它的子元素以了解它的大小以适应它的内容,而它不需要包装它的内容,因为它是一个可滚动的布局。

尝试将其设置为 0dip,使用 layout_weight="1" 以便为 TextView 留出空间:

<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(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15433456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com