如何从Explable ListView中从EditText获取文本



i具有可扩展的listView,该listView包含小时候的EDITTEXT,在此ExplinaBlElistView下方我有按钮时有按钮,然后我想从EditText中获取文本并存储在String中,我已经尝试了下面的getchildview方法中的代码

MyAdapter

public class ExListAdapter extends BaseExpandableListAdapter {
        private Activity context;
        private Map<String, List<String>> collections;
        private ArrayList<ListDetails> listItem;
        private TextView txtOk;
        public ExListAdapter(Activity context, ArrayList<ListDetails> listItem,
                                   Map<String, List<String>> collections, TextView txtOk) {
            this.context = context;
            this.collections = collections;
            this.listItem = listItem;
            this.txtOk = txtOk;
        }
        public Object getChild(int groupPosition, int childPosition) {
            return 1;
        }
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }
        @Nullable
        public View getChildView(final int groupPosition, final int childPosition,
                                 boolean isLastChild, @Nullable View convertView, ViewGroup parent) {
            LayoutInflater inflater = context.getLayoutInflater();
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.list_child, null);
            }
            etChild = (EditText) convertView.findViewById(R.id.etChild);
txtOk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    etChild.addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub
                }
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                                              int after) {
                    // TODO Auto-generated method stub
                }
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                    System.out.println("Value : " + childPosition + etChild.getText().toString());
                    Toast.makeText(context, etChild.getText().toString() + "...", Toast.LENGTH_SHORT).show();
                }
            });
            etChild.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    switch (event.getAction() & MotionEvent.ACTION_MASK) {
                        case MotionEvent.ACTION_UP:
                            v.getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                    }
                    return false;
                }
            });
            etChild.addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // TODO Auto-generated method stub
                }
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                                              int after) {
                    // TODO Auto-generated method stub
                }
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                    System.out.println("Value : " + childPosition + etChild.getText().toString());
                    Toast.makeText(context, etChild.getText().toString() + "...", Toast.LENGTH_SHORT).show();
                }
            });
            return convertView;
        }
        public int getChildrenCount(int groupPosition) {
            return 1;
        }
        public Object getGroup(int groupPosition) {
            return listItem.get(groupPosition).getValue();
        }
        public int getGroupCount() {
            return listItem.size();
        }
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }
        @Nullable
        public View getGroupView(final int groupPosition, boolean isExpanded,
                                 @Nullable View convertView, ViewGroup parent) {
            try {
                if (convertView == null) {
                    LayoutInflater infalInflater = (LayoutInflater) context
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    convertView = infalInflater.inflate(R.layout.list_group,
                            null);
                }
                TextView txtName = (TextView) convertView.findViewById(R.id.txtName);
                RelativeLayout rlList = (RelativeLayout) convertView.findViewById(R.id.rlList);
                txtName.setText(mArr.get(groupPosition).getValue());
            } catch (Exception e) {
                Logs.d("view- ExListAdapter", e, getClass().getSimpleName());
            }
            return convertView;
        }
        public boolean hasStableIds() {
            return true;
        }
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
        @Override
        public void onGroupCollapsed(int groupPosition) {
            try {
            } catch (Exception e) {
            }
            super.onGroupCollapsed(groupPosition);
        }
    }

但一直以来都是空白的,请Guyz帮助解决它!

您可以直接从 deDittext 中获得文字,就像下面的

一样
 txtOk.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                      String text=  etChild.getText().toString();
                      if(!text.isEmpty())
                      Toast.makeText(context,text  + "...",Toast.LENGTH_SHORT).show();

                });

最新更新