给Listview里面Item里的每一个控件怎么设定点击事件
2个回答
展开全部
这个主要是在自己自定义的Adapter中去实现
public class MyAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<String> data;
private Context mContext;
public UploadAdapter(Context context, List<String> data) {
this.mInflater = ((Activity)context).getLayoutInflater();
this.data = data;
this.mContext = context;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if(null == convertView) {
viewHolder = new ViewHolder();
//listview_item.xml为listview的item布局
convertView = mInflater.inflate(R.layout.listview_item, parent, false);
viewHolder.btn1 = (Button) convertView.findViewById(R.id.btn1);
viewHolder.btn2 = (Button) convertView.findViewById(R.id.btn2);
convertView.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TO-DO Something
}
});
viewHolder.btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TO-DO Something
}
});
return convertView;
}
private class ViewHolder {
public Button btn1;
public Button btn2;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询