android listVIew实现button按钮监听程序
1.重写simpleAdapter 方法
@Override public HashMap<String,String> getItem(int position) { // TODO Auto-generated method stub return listItem.get(position); } public MyAdapter(Context context, ArrayList<HashMap<String, String>> data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); this.context = context; listItem = data; GetLoginInfo(); } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub final int mPosition = position; convertView = super.getView(position, convertView, parent); Button deltebtn = (Button) convertView.findViewById(R.id.view_btn);// id为你自定义布局中按钮的id System.out.println(deltebtn.getText().toString()); TextView textView= (TextView)convertView.findViewById(R.id.QtyActual); System.out.println(textView.getText().toString()); String txtString= textView.getText().toString(); HashMap<String, String> map = getItem(mPosition); map.size(); System.out.println(txtString); deltebtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v ) { //监听事件方法 } }); return convertView; }
2.在Activity用调用
MyAdapter mScheduledetail = new MyAdapter (WorkTime.this, mylistdetail, R.layout.listview_wtitemdetail, new String[]
{ "111", "1111", "11111", "111111" }, new int[]
{ R.id.111, R.id.1111, R.id.11111q, R.id.111111 });
contentList = mylistdetail;
listView.setAdapter(mScheduledetail);
在你的activity中调用即可,
这里只提供核心代码,功能大家可以试一下,有问题大家可以进行交流。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。