【问题标题】:Groupview with Edittext in ExpandableListView在 ExpandableListView 中带有 Edittext 的 Groupview
【发布时间】:2016-05-09 13:58:37
【问题描述】:

我在 GroupView 中创建了一个带有 EditText 的 ExpandableListView。 是否有人知道如何保存(维护)GroupView 的 EditText 值?

【问题讨论】:

  • 这个问题基本上已经有答案了,你需要添加一个数据结构来包含一个项目的所有字符串,然后你需要将 addTextChangedListener 添加到 edittext 和 onTextChanged 你会需要将字符串保存在数据结构stackoverflow.com/questions/37096547/…
  • @visionixvisionix 我正在用edittext询问可扩展的列表视图组视图(父)

标签: android android-layout listview expandablelistview


【解决方案1】:

原理一样

//you need to allocate the data structure in size of the amount of items in your list
List<String> _retData = new ArrayList<String>(_data.size());   

@覆盖 public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    Holder h = null; //this will hold the edittext instances of eachItem in expand list
    if(convertView==null)
    {
        convertView = LayoutInflater.from(_context).inflate(android.R.layout.simple_expandable_list_item_2,
                parent, false);
        h = new Holder();
        h._editText = (EditText)convertView.findViewById(R.id.edit1);
        convertView.setTag(h);
    }
    else
    {
        h = (Holder)convertView.getTag();
    }

    //saving the data when the user write something... 
    h._editText.addTextChangedListener(new TextWatcher() {

       public void afterTextChanged(Editable s) {}

       public void beforeTextChanged(CharSequence s, int start,
         int count, int after) {
       }

       public void onTextChanged(CharSequence s, int start, int before, int count) {
         _retData.get(groupPosition)._itemPlant = s.toString();
       }
      });

}

你可以在我上面的评论中看到更详细的帖子

【讨论】:

  • 嗨“_retData.get(groupPosition)._itemPlant = s.toString();”你可以知道线路描述吗?并且一旦保存了edittext详细信息。同时单击groupwise旧值丢失。
  • 当您更改editText上的文本时,只有当用户更改文本时才会触发回调onTextChanged,您需要根据项目的groupPosition将其保存在_resData结构中,是否删除时的值groupItem 已关闭?
  • 如果你能描述什么不能正常工作什么现在工作会更有帮助?
  • 现在工作正常。我得到了解决方案。感谢您的支持
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多