在可扩展列表视图中存储edittext值的最佳方法是什么?

时间:2018-11-07 04:26:14

标签: android expandablelistview

我在可扩展列表视图中使用编辑文本。我将每个texbox值存储在hashmap中。但是问题是,当在 parent1 ed_00 中键入某些内容时,相同的文本会在 parent2 ed_30 中反映出来。使用onFocusChange侦听器将文本框值存储在哈希图中。

如果有人建议我,将文本框值保留在哈希图中的最佳方法是什么,将大有帮助。

代码

 @Override
public View getChildView(final int parent_position, final int child_position, boolean b, View view, ViewGroup viewGroup) {

   if (view == null) {
        holder = new ViewHolder();
        holder.editText = view.findViewById(R.id.txtRecordComment);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    //reading edittext value from hashmap
    holder.editText.setText(map.get("ed_"+child_position+""+parent_position));

    // storing key and value {"ed_00":"Hii",ed_01:"Hello"....}
    holder.editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (!hasFocus) {
                map.put("ed_" + child_position + "" + parent_position, holder.editText.getText().toString());
            }
        }
    });

 return view;
 }

0 个答案:

没有答案