我得到的只是一個值。我可以從我創建的所有editText中動態獲取數據,這樣我就可以在每個editText後使用逗號傳遞所有editText數據。我如何從動態生成的edittext中獲取價值?
這裏是我的代碼:
Diagnolist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText ed;
Integer count = 1;
final List<EditText> allEds = new ArrayList<EditText>();
for (int i = 0; i < count; i++) {
ed = new EditText(MainActivity.this);
allEds.add(ed);
ed.setId(i);
ed.setHint("add diagonis");
ed.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
addDiagnosis.addView(ed);
}
Toast_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] strings = new String[(allEds.size())];
String st = "";
for(int i=0; i < allEds.size(); i++){
strings[i] = allEds.get(i).getText().toString();
st = strings[i]+"," +st;
Toast.makeText(MainActivity.this, st, Toast.LENGTH_SHORT).show();
}
}
});
}
});
edittext1 = aaaa editext2:bbbbb我越來越首先aaaa然後aaaa,bbbbb –
我更新了我的code.please試試上面的代碼st + = strings [i] +「,」; – Vasant