的EditText TextChangeListener被多次 [英] EditText TextChangeListener called multiple times
问题描述
在此特定情形的ExpandableList是假设显示2名单组。当用户选择的复选框,则添加该值到的EditText并且那那里所示的输出部分的TextChangeListener被激发为第一输入3次和1次为第二
在上的EditText变化检查收到的意见均
22448在ArrayList中的0项
块引用>&安培;
56.12在ArrayList中的第一个项目
块引用>code
公共类ExpandableListAdapter扩展BaseExpandableListAdapter { 私人LayoutInflater吹气;
私人上下文的背景下;
私人ExpandableListView手风琴;
私人诠释lastExpandedGroupPosition;
ArrayList的< ModelObject> mParent;
TextView的textViewLabelGrandTotal;
浮grandTotal = 0; 公共ExpandableListAdapter(上下文的背景下,ArrayList的< ModelObject> ModelObject,ExpandableListView手风琴,TextView的textViewLabelGrandTotal)
{ mParent = ModelObject;
充气= LayoutInflater.from(上下文);
this.accordion =手风琴;
this.context =背景;
this.textViewLabelGrandTotal = textViewLabelGrandTotal;
} @覆盖
//计数组/父项的数量,以便在列表知道多少次调用getGroupView()方法
公众诠释getGroupCount(){
返回mParent.size();
} @覆盖
//计数儿童物品所以列表知道多少次调用的次数getChildView()方法
公众诠释getChildrenCount(int i)以{
返回mParent.get(我).childCount;
} @覆盖
//获取每个父母/组的冠军
公共对象getGroup(int i)以{
返回mParent.get(我).INVOICE_ID;
} @覆盖
//获取每个项目的名称
公共对象getChild(INT I,INT I1){
返回mParent.get(ⅰ).children.get(I1);
} @覆盖
众长getGroupId(int i)以{
返回我;
} @覆盖
众长getChildId(INT I,INT I1){
返回I1;
} @覆盖
公共布尔hasStableIds(){
返回true;
} @覆盖
//这个方法,你必须将文本设置为在列表中看到父/组
公共查看getGroupView(最终诠释我,布尔B,观景,ViewGroup中的ViewGroup){
如果(查看== NULL){
鉴于= inflater.inflate(R.layout.sfa_receipt_by_customer_new_receipt_due_invoice_list_item_parent,ViewGroup中,FALSE);
}
//设置类别名称为标记,以便视图可以创建视图后
view.setTag(getGroup(ⅰ)的ToString()); 复选框CheckBoxInv =(复选框)view.findViewById(R.id.CheckBoxInv);
TextView的textViewLabelInvoice =(TextView中)view.findViewById(R.id.textViewLabelInvoice);
TextView的textViewLabelDate =(TextView中)view.findViewById(R.id.textViewLabelDate);
TextView的textViewDueAmt =(TextView中)view.findViewById(R.id.textViewDueAmt);
TextView的textViewRemainingAmt =(TextView中)view.findViewById(R.id.textViewRemainingAmt);
最终的EditText editTextPaid =(EditText上)view.findViewById(R.id.editTextPaid); DecimalFormat的DF =新的DecimalFormat(###);
textViewLabelInvoice.setText(mParent.get㈠.INVOICE_NO);
textViewLabelDate.setText(mParent.get㈠.INVOICE_DATE);
textViewDueAmt.setText(df.format(mParent.get(ⅰ)。由于));
textViewRemainingAmt.setText(df.format(mParent.get㈠.REMAINING_AFTER_PAID));
CheckBoxInv.setChecked(mParent.get㈠.checked); CheckBoxInv.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){ 复选框C =(复选框)V; 的System.out.println(=====================检查变化listerner =================== =========);
editTextPaid.setText(df.format(mParent.get(ⅰ)。由于)); // editTextPaid.setText();
的System.out.println(=====================检查变化listerner =================== =========); 如果(c.isChecked()== FALSE)
{
的System.out.println(=====================取消选中变化listerner =================== =========);
editTextPaid.setText();
的System.out.println(=====================取消选中变化listerner =================== =========);
}
// notifyDataSetChanged();
}
}); //启用编辑文本框的焦点
editTextPaid.setOnTouchListener(新View.OnTouchListener(){ @覆盖
公共布尔onTouch(视图V,MotionEvent事件){ 的System.out.println(触摸LISTERNER);
返回false;
}
}); //的EditText框禁用焦点
editTextPaid.setOnFocusChangeListener(新View.OnFocusChangeListener(){ 公共无效onFocusChange(视图V,布尔hasFocus){
的System.out.println(焦点变化监听);
}
}); //重新计算剩余余额
editTextPaid.addTextChangedListener(新TextWatcher(){ @覆盖
公共无效onTextChanged(CharSequence的为arg0,ARG1 INT,INT ARG2,诠释ARG3){
的System.out.println(基于文本更改); } @覆盖
公共无效beforeTextChanged(CharSequence的为arg0,ARG1 INT,INT ARG2,
INT ARG3){
的System.out.println(以前TEXT CHANGE);
} @覆盖
公共无效afterTextChanged(编辑为arg0){ 的System.out.println(之后TEXT CHANGE); }
});
//返回整个视图
返回视图。
}
@覆盖
//这个方法,你必须将文本看到孩子就行了
公共查看getChildView(INT I,INT I1,布尔B,观景,ViewGroup中的ViewGroup){
如果(查看== NULL)
{
鉴于= inflater.inflate(R.layout.sfa_receipt_by_customer_new_receipt_due_invoice_list_item_child,ViewGroup中,FALSE);
}
的System.out.println(内部getChildView().................. !!);
TextView的textViewLabelReceipt =(TextView中)view.findViewById(R.id.textViewLabelReceipt);
textViewLabelReceipt.setText((I1 + 1)+ mParent.get(ⅰ).children.get(I1).RECEIPT_NO。); TextView的textViewLabelDate =(TextView中)view.findViewById(R.id.textViewLabelDate);
textViewLabelDate.setText((I1 + 1)+ mParent.get(ⅰ).children.get(I1).RECEIPT_DATE。); TextView的textViewRemainingAmt =(TextView中)view.findViewById(R.id.textViewRemainingAmt);
textViewRemainingAmt.setText((i1+1)+\".\"+mParent.get(i).children.get(i1).REMAINING_AFTER_ADJUSTED_AMOUNT); TextView的textViewDueAmt =(TextView中)view.findViewById(R.id.textViewDueAmt);
textViewDueAmt.setText((I1 + 1)+ mParent.get(ⅰ).children.get(I1).ADVANCE_BALANCE。); 的EditText editTextPaid =(EditText上)view.findViewById(R.id.editTextPaid); 返回视图。
} @覆盖
公共布尔isChildSelectable(INT I,INT I1){
返回true;
} @覆盖
/ **
*自动折叠最后扩展群
* /
公共无效onGroupExpanded(INT groupPosition){ 如果(groupPosition!= lastExpandedGroupPosition){
accordion.collapseGroup(lastExpandedGroupPosition);
}
super.onGroupExpanded(groupPosition);
lastExpandedGroupPosition = groupPosition;
}}输出:
4月7日至30日:06:47.662 1432年至1432年/? I / System.out的:=====================检查变化listerner ==================== ========
07-30 04:06:47.662 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:47.662 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:47.666 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:47.666 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:47.666 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:47.666 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:47.666 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:47.666 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:47.666 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:47.666 1432年至1432年/? I / System.out的:=====================检查变化listerner ==================== ========
07-30 04:06:58.822 1432年至1432年/? I / System.out的:=====================检查变化listerner ==================== ========
07-30 04:06:58.822 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:58.822 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:58.822 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:58.826 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:58.826 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:58.826 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:58.826 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:58.826 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:58.830 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:58.830 1432年至1432年/? I / System.out的:=====================检查变化listerner ==================== ========
07-30 04:06:58.830 1432年至1432年/? I / System.out的:=====================取消选中变化listerner ==================== ========
07-30 04:06:58.830 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:58.830 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:58.830 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:58.834 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:58.834 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:58.834 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:58.834 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:这一点:com.example.ExpandableListAdapter$4@52a697d0
07-30 04:06:58.834 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:这一点:com.example.ExpandableListAdapter$4@528a1cfc
07-30 04:06:58.834 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:这一点:com.example.ExpandableListAdapter$4@52882534
07-30 04:06:58.834 1432年至1432年/? I / System.out的:=====================取消选中变化listerner ==================== ========
07-30 04:07:03.337 1432年至1432年/? I / System.out的:=====================检查变化listerner ==================== ========
07-30 04:07:03.337 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:03.337 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:ARG2 0:0参数3:9这样的:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:03.337 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:03.337 1432年至1432年/? I / System.out的:com.example.ExpandableListAdapter@52ae033c:=====================检查变化listerner ============ ================
07-30 04:07:06.053 1432年至1432年/? I / System.out的:com.example.ExpandableListAdapter@52ae033c:=====================检查变化listerner ============ ================
07-30 04:07:06.057 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:06.057 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:9这样的:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:06.057 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:有些文字是:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:06.057 1432年至1432年/? I / System.out的:=====================检查变化listerner ==================== ========
07-30 04:07:06.057 1432年至1432年/? I / System.out的:=====================取消选中变化listerner ==================== ========
07-30 04:07:06.057 1432年至1432年/? I / System.out的:之前文本更改>>>将arg0:某些文本ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:06.057 1432年至1432年/? I / System.out的:基于文本更改>>>将arg0:ARG1:0 ARG2:9 ARG3:0这样的:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:06.085 1432年至1432年/? I / System.out的:后面的文本CHANGE>>>将arg0:这一点:com.example.ExpandableListAdapter$4@52bd946c
07-30 04:07:06.085 1432年至1432年/? I / System.out的:=====================取消选中变化listerner ==================== ========ExpandableList GroupView
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / LIST_ITEM> <复选框
机器人:ID =@ + ID / CheckBoxInv
机器人:layout_width =WRAP_CONTENT
机器人:可聚焦=假
机器人:layout_height =WRAP_CONTENT/> <的TextView
机器人:ID =@ + ID / textViewLabelInvoice
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字样式=大胆
机器人:layout_toRightOf =@ + ID / CheckBoxInv
机器人:文字=IV14AA00040000001
/> <的TextView
机器人:ID =@ + ID / textViewLabelDate
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / textViewDueAmt
机器人:layout_toRightOf =@ + ID / CheckBoxInv
机器人:文字=2014年12月15日/> <的TextView
机器人:ID =@ + ID / textViewLabelRemainingAmt
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / textViewDueAmt
机器人:layout_toRightOf =@ + ID / textViewLabelDate
机器人:layout_marginLeft =5DP
机器人:文字=剩余/> <的TextView
机器人:ID =@ + ID / textViewRemainingAmt
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / textViewDueAmt
机器人:layout_alignParentRight =真
机器人:layout_marginLeft =5DP
机器人:文字=1000.00/> <的TextView
机器人:ID =@ + ID / textViewDueAmt
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:文字样式=大胆
机器人:TEXTSIZE =16SP
机器人:文字=10000.00
/> <的EditText
机器人:ID =@ + ID / editTextPaid
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / textViewLabelDate
机器人:可聚焦=假
机器人:重力=右
机器人:提示=0.00
安卓的inputType =TEXT | textNoSuggestions | numberDecimal/>< / RelativeLayout的>
解决方案解决它自己。
配售所有视图[复选框,EDITTEXT,TextView的]为ViewHolder类[这是什么,但包含的观点类]内getGroupView()方法。
使用视图对象这是getGroupView()方法的参数,如果查看参数返回null的settag()方法保存它。
检索使用getTag()的意见和初始化ViewHolder对象从它,如果查看参数不为null。
In this particular scenario the ExpandableList is suppose to show 2 list as group. When a user selects the checkbox, it add the value to the EditText and thats where the TextChangeListener is fired up 3 times for the first input and 1 time for the second as shown in the output section.
The inputs received by the EditText on check change were
22448 for the 0 item in the arraylist
&
56.12 for the 1st item in the arraylist
Code
public class ExpandableListAdapter extends BaseExpandableListAdapter { private LayoutInflater inflater; private Context context; private ExpandableListView accordion; private int lastExpandedGroupPosition; ArrayList<ModelObject> mParent; TextView textViewLabelGrandTotal; float grandTotal = 0; public ExpandableListAdapter( Context context, ArrayList<ModelObject> ModelObject, ExpandableListView accordion, TextView textViewLabelGrandTotal) { mParent = ModelObject; inflater = LayoutInflater.from(context); this.accordion = accordion; this.context=context; this.textViewLabelGrandTotal=textViewLabelGrandTotal; } @Override //counts the number of group/parent items so the list knows how many times calls getGroupView() method public int getGroupCount() { return mParent.size(); } @Override //counts the number of children items so the list knows how many times calls getChildView() method public int getChildrenCount(int i) { return mParent.get(i).childCount; } @Override //gets the title of each parent/group public Object getGroup(int i) { return mParent.get(i).INVOICE_ID; } @Override //gets the name of each item public Object getChild(int i, int i1) { return mParent.get(i).children.get(i1); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i1) { return i1; } @Override public boolean hasStableIds() { return true; } @Override //in this method you must set the text to see the parent/group on the list public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) { if (view == null) { view = inflater.inflate(R.layout.sfa_receipt_by_customer_new_receipt_due_invoice_list_item_parent, viewGroup,false); } // set category name as tag so view can be found view later view.setTag(getGroup(i).toString()); CheckBox CheckBoxInv =(CheckBox)view.findViewById(R.id.CheckBoxInv); TextView textViewLabelInvoice = (TextView) view.findViewById(R.id.textViewLabelInvoice); TextView textViewLabelDate = (TextView) view.findViewById(R.id.textViewLabelDate); TextView textViewDueAmt = (TextView) view.findViewById(R.id.textViewDueAmt); TextView textViewRemainingAmt = (TextView) view.findViewById(R.id.textViewRemainingAmt); final EditText editTextPaid = (EditText)view.findViewById(R.id.editTextPaid); DecimalFormat df = new DecimalFormat("#.##"); textViewLabelInvoice.setText(mParent.get(i).INVOICE_NO); textViewLabelDate.setText(mParent.get(i).INVOICE_DATE); textViewDueAmt.setText(df.format(mParent.get(i).DUE)); textViewRemainingAmt.setText(df.format(mParent.get(i).REMAINING_AFTER_PAID)); CheckBoxInv.setChecked(mParent.get(i).checked); CheckBoxInv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBox c = (CheckBox) v; System.out.println("===================== check change listerner ============================"); editTextPaid.setText(df.format(mParent.get(i).DUE)); // editTextPaid.setText(""); System.out.println("===================== check change listerner ============================"); if(c.isChecked() == false) { System.out.println("===================== uncheck change listerner ============================"); editTextPaid.setText(""); System.out.println("===================== uncheck change listerner ============================"); } // notifyDataSetChanged(); } }); //enable focus of edit text box editTextPaid.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { System.out.println("ON TOUCH LISTERNER"); return false; } }); //disable focus of edittext box editTextPaid.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { System.out.println("ON FOCUS CHANGE LISTENER"); } }); //re calculate the remaining balance amount editTextPaid.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { System.out.println("ON TEXT CHANGE"); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { System.out.println("BEFORE TEXT CHANGE"); } @Override public void afterTextChanged(Editable arg0) { System.out.println("AFTER TEXT CHANGE"); } }); //return the entire view return view; } @Override //in this method you must set the text to see the children on the list public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) { if (view == null) { view = inflater.inflate(R.layout.sfa_receipt_by_customer_new_receipt_due_invoice_list_item_child, viewGroup,false); } System.out.println("Inside getChildView()..................!!"); TextView textViewLabelReceipt = (TextView) view.findViewById(R.id.textViewLabelReceipt); textViewLabelReceipt.setText((i1+1)+"."+mParent.get(i).children.get(i1).RECEIPT_NO); TextView textViewLabelDate = (TextView) view.findViewById(R.id.textViewLabelDate); textViewLabelDate.setText((i1+1)+"."+mParent.get(i).children.get(i1).RECEIPT_DATE); TextView textViewRemainingAmt = (TextView) view.findViewById(R.id.textViewRemainingAmt); textViewRemainingAmt.setText((i1+1)+"."+mParent.get(i).children.get(i1).REMAINING_AFTER_ADJUSTED_AMOUNT); TextView textViewDueAmt = (TextView) view.findViewById(R.id.textViewDueAmt); textViewDueAmt.setText((i1+1)+"."+mParent.get(i).children.get(i1).ADVANCE_BALANCE); EditText editTextPaid =(EditText)view.findViewById(R.id.editTextPaid); return view; } @Override public boolean isChildSelectable(int i, int i1) { return true; } @Override /** * automatically collapse last expanded group */ public void onGroupExpanded(int groupPosition) { if(groupPosition != lastExpandedGroupPosition){ accordion.collapseGroup(lastExpandedGroupPosition); } super.onGroupExpanded(groupPosition); lastExpandedGroupPosition = groupPosition; } }
Output:
07-30 04:06:47.662 1432-1432/? I/System.out﹕ ===================== check change listerner ============================ 07-30 04:06:47.662 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:47.662 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:47.666 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:47.666 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:47.666 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:47.666 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:47.666 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:47.666 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:47.666 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:47.666 1432-1432/? I/System.out﹕ ===================== check change listerner ============================ 07-30 04:06:58.822 1432-1432/? I/System.out﹕ ===================== check change listerner ============================ 07-30 04:06:58.822 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:58.822 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:58.822 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:58.826 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:58.826 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:58.826 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:58.826 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:58.826 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:58.830 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:58.830 1432-1432/? I/System.out﹕ ===================== check change listerner ============================ 07-30 04:06:58.830 1432-1432/? I/System.out﹕ ===================== uncheck change listerner ============================ 07-30 04:06:58.830 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:58.830 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:58.830 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:58.834 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:58.834 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:58.834 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:58.834 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: this: com.example.ExpandableListAdapter$4@52a697d0 07-30 04:06:58.834 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: this: com.example.ExpandableListAdapter$4@528a1cfc 07-30 04:06:58.834 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: this: com.example.ExpandableListAdapter$4@52882534 07-30 04:06:58.834 1432-1432/? I/System.out﹕ ===================== uncheck change listerner ============================ 07-30 04:07:03.337 1432-1432/? I/System.out﹕ ===================== check change listerner ============================ 07-30 04:07:03.337 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:03.337 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 0 arg3: 9 this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:03.337 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:03.337 1432-1432/? I/System.out﹕ com.example.ExpandableListAdapter@52ae033c : ===================== check change listerner ============================ 07-30 04:07:06.053 1432-1432/? I/System.out﹕ com.example.ExpandableListAdapter@52ae033c : ===================== check change listerner ============================ 07-30 04:07:06.057 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:06.057 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 9 this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:06.057 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: Some text this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:06.057 1432-1432/? I/System.out﹕ ===================== check change listerner ============================ 07-30 04:07:06.057 1432-1432/? I/System.out﹕ ===================== uncheck change listerner ============================ 07-30 04:07:06.057 1432-1432/? I/System.out﹕ BEFORE TEXT CHANGE >>> arg0: Some text arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:06.057 1432-1432/? I/System.out﹕ ON TEXT CHANGE >>> arg0: arg1: 0 arg2: 9 arg3: 0 this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:06.085 1432-1432/? I/System.out﹕ AFTER TEXT CHANGE >>> arg0: this: com.example.ExpandableListAdapter$4@52bd946c 07-30 04:07:06.085 1432-1432/? I/System.out﹕ ===================== uncheck change listerner ============================
ExpandableList GroupView
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/list_item"> <CheckBox android:id="@+id/CheckBoxInv" android:layout_width="wrap_content" android:focusable="false" android:layout_height="wrap_content" /> <TextView android:id="@+id/textViewLabelInvoice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:layout_toRightOf="@+id/CheckBoxInv" android:text="IV14AA00040000001" /> <TextView android:id="@+id/textViewLabelDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textViewDueAmt" android:layout_toRightOf="@+id/CheckBoxInv" android:text="15.12.2014" /> <TextView android:id="@+id/textViewLabelRemainingAmt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textViewDueAmt" android:layout_toRightOf="@+id/textViewLabelDate" android:layout_marginLeft="5dp" android:text="Remaining" /> <TextView android:id="@+id/textViewRemainingAmt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textViewDueAmt" android:layout_alignParentRight="true" android:layout_marginLeft="5dp" android:text="1000.00" /> <TextView android:id="@+id/textViewDueAmt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:textStyle="bold" android:textSize="16sp" android:text="10000.00" /> <EditText android:id="@+id/editTextPaid" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/textViewLabelDate" android:focusable="false" android:gravity="right" android:hint="0.00" android:inputType="text|textNoSuggestions|numberDecimal" /> </RelativeLayout>
解决方案Solved it myself.
Placed all the view[CHECKBOX, EDITTEXT, TEXTVIEW] for the getGroupView() method within ViewHolder class [which is nothing but a class which contain views].
Saved it using settag() method of the "view" object which is a parameter of the getGroupView() method if the "view" parameter returned null.
Retrieved the views using getTag() and initialized the ViewHolder object from it if the "view" parameter is not null.
这篇关于的EditText TextChangeListener被多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!