android中如何在Hashmap中存储动态编辑文本值
我有多个动态编辑文本框android中如何在Hashmap中存储动态编辑文本值,android,hashmap,Android,Hashmap,我有多个动态编辑文本框 TableLayout ll_list = (TableLayout) findViewById(R.id.tbl); for(i=0;i < Sizedd; i++) { EditText ed_comm = new EditText(this); ll_list.addView(ed_comm); } 如何在hashmap中存储其值?您可以做的是,为您创建的每个EditText设置标记,并使用Text Watcher存储它们的数据。我不擅长这个。但是试着相应地
TableLayout ll_list = (TableLayout) findViewById(R.id.tbl);
for(i=0;i < Sizedd; i++)
{
EditText ed_comm = new EditText(this);
ll_list.addView(ed_comm);
}
如何在hashmap中存储其值?您可以做的是,为您创建的每个EditText设置标记,并使用Text Watcher存储它们的数据。我不擅长这个。但是试着相应地修改我的代码片段 首先全局声明一个HashMap
public HashMap<Integer,String> myList=new HashMap<Integer,String>();
使用edittext的id作为键,文本作为值?不要创建重复的问题。不到2小时前,您已经问过这个问题。请使用hashmap\u name=new hashmap创建hashmap;并使用map_name.puta_字符串,另一个_字符串;使用edittext_id.getText从edittext获取值。任何人都可以为用户1153176提供示例吗希望我的回答至少能有所帮助。我有按钮,当我单击按钮时,它的call system.out.PrintlnmyList;它显示出{2=zxc}是的。您应该只在第二个编辑文本中输入文本。尝试编辑所有编辑文本并选中
TableLayout ll_list = (TableLayout) findViewById(R.id.tbl);
for(i=0;i < Sizedd; i++)
{
EditText ed_comm = new EditText(this);
ed_comm.setTag(i); // By this you have set an Tag to the editText and hence you can find out which editText it is, in the TextWatcher implementation.
ll_list.addView(ed_comm);
ed_comm.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
Log.i("After Text","Called");
myList.put(ed_comm.getTag(),s.toString().trim());
}
});
}
Iterator i = myList.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}