怎么给listview的item里面的控件加点击事件
1个回答
2015-08-16 · 知道合伙人软件行家
关注
展开全部
public class MyAdapter extends BaseAdapter {
private List<User> users;
private int resource;
private LayoutInflater inflater;
private Context context;
public MyAdapter(List<User> users, Context context, int resource,
String user_qq) {
this.users = users;
this.resource = resource;
this.context = context;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return users.size();
}
@Override
public Object getItem(int position) {
return users.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(resource, null);
}
User user = users.get(position);
//获取控件
Button button = (Button) convertView.findViewById(R.id.remark);
//为控件设置数据
button.setText("评论");
//设置监听事件
button.setOnclickListener(new View(
............
));
return convertView;
}
}
private List<User> users;
private int resource;
private LayoutInflater inflater;
private Context context;
public MyAdapter(List<User> users, Context context, int resource,
String user_qq) {
this.users = users;
this.resource = resource;
this.context = context;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return users.size();
}
@Override
public Object getItem(int position) {
return users.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(resource, null);
}
User user = users.get(position);
//获取控件
Button button = (Button) convertView.findViewById(R.id.remark);
//为控件设置数据
button.setText("评论");
//设置监听事件
button.setOnclickListener(new View(
............
));
return convertView;
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询