读取文件略:
对与listView要重写一个自己的adapter,其中edittext要设置OnTouch监听及TextWatcher来获取更改后的值
public View getView(final int position,View convertView,ViewGroup parent) { //TODO Auto-generated method stub //取得layout LayoutInflater factory = LayoutInflater.from(this.context); View view =factory.inflate(R.layout.qw_appserver_item,null); HashMap map = data.get(position); tv = (TextView)view.findViewById(R.id.qw_appserver_textview); //设置值 tv.setText((String)map.get("id")); et = (EditText)view.findViewById(R.id.qw_appserver_editview); et.setText((String)map.get("value")); et.setTag(position); //设置OnTouchListener监听,判断是否取到了当前EditText的焦点 et.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v,MotionEvent event) { System.out.println("--et ontouchlis---"); if (event.getAction() == MotionEvent.ACTION_UP) { index = (Integer) v.getTag(); System.out.println("--et index---"+index); } return false; } }); //失去焦点 et.clearFocus(); if (index != -1 && index == position) { //获取焦点 et.requestFocus(); } //内部类,当editText的值改变时把值取到放到对应的list上, class MyTextWatcher implements TextWatcher { public MyTextWatcher() { } @Override public void onTextChanged(CharSequence s,int start,int before,int count) { } @Override public void beforeTextChanged(CharSequence s,int count,int after) { } @Override public void afterTextChanged(Editable s) { if(index != -1 && index == position){ if (s != null && !"".equals(s.toString())) { //data数据源,能在activity中取到变化过的data的值 data.get(index).put("value",s.toString());// 当EditText数据发生改变的时候存到data变量中 //System.out.println("--s.tostring--"+s.toString()+" position:"+index); } }else{ if (s != null && !"".equals(s.toString())) { int position = (Integer) et.getTag(); data.get(position).put("value",s.toString());// 当EditText数据发生改变的时候存到data变量中 //System.out.println("--s.tostring--"+s.toString()+" position:"+position); } } } } et.addTextChangedListener(new MyTextWatcher()); return view; }原文链接:https://www.f2er.com/xml/300046.html