2017-08-15 61 views
0

選中複選框後,我創建一個EditText視圖並保存選中的值。在數據輸入後保存edittext值

if (checked){ 
     //add to array 
     checkIn.add(boxName); 
     mLayout.addView(createNewEditText(boxNumber),count+1); 
     //set focus and open keyboard 
     EditText editText = (EditText) findViewById(100+ Integer.parseInt(boxNumber)); 
     editText.requestFocus(); 
    }else { 
     //remove from array 
     checkIn.remove(boxName); 
     int intTextId = Integer.parseInt(boxNumber); 
     mLayout.removeView(findViewById(100+intTextId)); 
    } 

接下來用戶可以在EditText中輸入數據。 我想在輸入數據後保存該值。

我搜查了谷歌搜索並沒有找到任何東西。

任何想法

+1

要動態創建編輯文本,或者是你展示它,當一個複選框被選中?一次顯示多少個編輯文本?似乎是一個更好的主意,只是隱藏編輯文本onCreate,然後顯示它時,該框被選中。 – DroiDev

+0

是否有任何保存按鈕,或者您想在用戶暫停鍵入一段指定時間後保存數據 –

+0

我正在動態創建編輯文本。該列表可以是30 +複選框。每個選中的複選框都添加了一個編輯文本。未選中時刪除。 –

回答

0

您可以使用TextChangedListener:

editText.addTextChangedListener(new TextWatcher() { 

     public void afterTextChanged(Editable s) 
     { 
     //do something with your text 
     } 

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

     public void onTextChanged(CharSequence s, int start, int before, int count) {} 
    }); 
} 
+0

何時觸發afterTextChanged和onTextChanged? –

+0

[檢查此答案](https://stackoverflow.com/a/26994592/6241160) – Rysiu