2016-05-09 4 views
-1

GroupViewでEditTextを使ってExpandableListViewを作成しました。 GroupViewのEditText値を保存(維持)する方法を知っている人がいますか?ExpandableListViewのEdittextを使ったGroupview

+0

基本的には、この質問にはすでに回答があるかもしれません。ある項目のすべての文字列を含むデータ構造を追加する必要があります。次にaddTextChangedListenerをedittextに追加し、onTextChangedに文字列を保存する必要があります。データ構造 http://stackoverflow.com/questions/37096547/how-to-get-data-from-edit-text-in-a-recyclerview/37097190#37097190 –

+0

@visionixvisionix拡張可能リストビューgroupview(親) with edittext –

答えて

0

これと同じ原理

//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()); 

@Override パブリックビューgetGroupView(最終int型groupPosition、ブールisExpandedとして、 ビューconvertView、のViewGroupの親){

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(); 
     } 
     }); 

}

ます上記の私のコメントの投稿を詳細で見ることができます

+0

こんにちは "_retData.get(groupPosition)._ itemPlant = s.toString();"あなたは回線の説明を知っているかもしれません。また、一度edittextの詳細を保存しました。グループ単位の古い値をクリックすると、値が欠落します。 –

+0

editTextのテキストを変更すると、onTextChangedがコールバックされます。ユーザーがテキストを変更したときにのみ、アイテムのgroupPositionに従って_resData構造体に保存する必要があります。groupItemが閉じられたときに値を削除しますか? –

+0

この例には何も問題はありません –

関連する問題