android listview中多个edittext监听取值

xqq12345 2014-11-27 05:44:00
如题,一个edittext可以成功取值,那么多个怎么监听,求大神指教!

public final class ViewHolder {
public TextView in_goods_id;
public TextView goodsName;
public EditText quanity;
public EditText produtionDate;
public EditText location;
public EditText batch;
}

public class MyAdapter extends BaseAdapter {

private LayoutInflater flater;

public MyAdapter(Context context,List<Map<String, Object>> data) {
super();
this.flater = LayoutInflater.from(context);
}

public int getCount() {
// TODO Auto-generated method stub
return list2.size();
}

public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private Integer index = -1;

public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = flater.inflate(R.layout.in_goods_list, null);
holder.in_goods_id = (TextView) convertView
.findViewById(R.id.in_goods_id);
holder.goodsName = (TextView) convertView
.findViewById(R.id.goodsName);
holder.quanity = (EditText) convertView
.findViewById(R.id.quanity);
holder.produtionDate = (EditText) convertView
.findViewById(R.id.produtionDate);
holder.location = (EditText) convertView
.findViewById(R.id.location);
holder.batch = (EditText) convertView.findViewById(R.id.batch);

holder.quanity.setTag(position);
holder.quanity.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_UP) {
index = (Integer) view.getTag();
}
return false;
}
});
class MyTextWatcher implements TextWatcher {
public MyTextWatcher(ViewHolder holder) {
mHolder = holder;
}

private ViewHolder mHolder;

@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}

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

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (s != null && !"".equals(s.toString())) {
int position = (Integer) mHolder.quanity.getTag();
list2.get(position).put("quanity", s.toString());// 当EditText数据发生改变的时候存到data变量中
for (Map<String, Object> m : list2) {
for (String k : m.keySet()) {
System.out.println(k + " : " + m.get(k));
}
}
}
}
}

holder.quanity
.addTextChangedListener(new MyTextWatcher(holder));
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
holder.quanity.setTag(position);

}
...全文
738 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
学习者mm 2015-09-22
  • 打赏
  • 举报
回复
是怎么解决的我也遇到了这个问题
漂流的代码 2014-11-28
  • 打赏
  • 举报
回复
mHolder.quanity不就是edit吗?
xqq12345 2014-11-28
  • 打赏
  • 举报
回复
引用 5 楼 u010694585 的回复:
他们id是不一样的啊
用最笨的方法解决了,但是希望有好一点的方法
xqq12345 2014-11-28
  • 打赏
  • 举报
回复
引用 5 楼 u010694585 的回复:
他们id是不一样的啊
怎么通过id判断呢,可以指点一下吗?
红袖满楼招 2014-11-28
  • 打赏
  • 举报
回复
他们id是不一样的啊
xqq12345 2014-11-28
  • 打赏
  • 举报
回复
大神们指点一下啊!
xqq12345 2014-11-27
  • 打赏
  • 举报
回复
引用 1 楼 u010694585 的回复:
能取一个难道不能取多个?
怎么判断修改的是哪一个呢?

public final class ViewHolder {
        public TextView in_goods_id;
        public TextView goodsName;
        public EditText quanity;
        public EditText produtionDate;
        public EditText location;
        public EditText batch;
    }
 
    public class MyAdapter extends BaseAdapter {
 
        private LayoutInflater flater;
 
        public MyAdapter(Context context,List<Map<String, Object>> data) {
            super();
            this.flater = LayoutInflater.from(context);
        }
 
        public int getCount() {
            // TODO Auto-generated method stub
            return list2.size();
        }
 
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }
 
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }
        private Integer index = -1;
 
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = flater.inflate(R.layout.in_goods_list, null);
                holder.in_goods_id = (TextView) convertView
                        .findViewById(R.id.in_goods_id);
                holder.goodsName = (TextView) convertView
                        .findViewById(R.id.goodsName);
                holder.quanity = (EditText) convertView
                        .findViewById(R.id.quanity);
                holder.produtionDate = (EditText) convertView
                        .findViewById(R.id.produtionDate);
                holder.location = (EditText) convertView
                        .findViewById(R.id.location);
                holder.batch = (EditText) convertView.findViewById(R.id.batch);
                 
                <span style="color: #FF0000;">holder.quanity.setTag(position);
                holder.quanity.setOnTouchListener(new OnTouchListener() {
 
                    @Override
                    public boolean onTouch(View view, MotionEvent event) {
                        // TODO Auto-generated method stub
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            index = (Integer) view.getTag();
                        }
                        return false;
                    }
                });
                class MyTextWatcher implements TextWatcher {
                    public MyTextWatcher(ViewHolder holder) {
                        mHolder = holder;
                    }
 
                    private ViewHolder mHolder;
 
                    @Override
                    public void onTextChanged(CharSequence s, int start,
                            int before, int count) {
                    }
 
                    @Override
                    public void beforeTextChanged(CharSequence s, int start,
                            int count, int after) {
                    }
 
                    @Override
                    public void afterTextChanged(Editable s) {
                        // TODO Auto-generated method stub
                        if (s != null && !"".equals(s.toString())) {
                            int position = (Integer) mHolder.quanity.getTag();
                            list2.get(position).put("quanity", s.toString());// 当EditText数据发生改变的时候存到data变量中
                            for (Map<String, Object> m : list2) {
                                for (String k : m.keySet()) {
                                    System.out.println(k + " : " + m.get(k));
                                }
                            }
                        }
                    }
                }</span>
                holder.quanity
                        .addTextChangedListener(new MyTextWatcher(holder));
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
                holder.quanity.setTag(position);
 
            }
这边都已经写死了啊
红袖满楼招 2014-11-27
  • 打赏
  • 举报
回复
能取一个难道不能取多个?

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧