1.重写simpleAdapter 方法 @Override public HashMapgetItem(int position) { // TODO Auto-generated method stub return listItem.get(position); } public MyAdapter(Context context, ArrayList > 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 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中调用即可, 这里只提供核心代码,功能大家可以试一下,有问题大家可以进行交流。