listview 里面有button怎么设置点击事件
1个回答
展开全部
需要自定义LISTVIEW的适配器。在getview方法里面设置三个button的点击事件。
给个例子你:
private class TestAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Context con;
public TestAdapter (Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
con = context;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return list.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list, null);
holder = new ViewHolder();
holder.bt01 = (Button) convertView.findViewById(R.id.bt01);
holder.bt02 = (Button) convertView.findViewById(R.id.bt02);
holder.bt03 = (Button) convertView.findViewById(R.id.bt03);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final int arg = position;
//bt01点击
holder.bt01.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View v) {
}
});
//bt02点击
holder.bt02.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View v) {
}
});
//bt03点击
holder.bt03.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View v) {
}
});
return convertView;
}
class ViewHolder {
Button bt01;
Button bt02;
Button bt03;
}
}
给个例子你:
private class TestAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Context con;
public TestAdapter (Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
con = context;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return list.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list, null);
holder = new ViewHolder();
holder.bt01 = (Button) convertView.findViewById(R.id.bt01);
holder.bt02 = (Button) convertView.findViewById(R.id.bt02);
holder.bt03 = (Button) convertView.findViewById(R.id.bt03);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final int arg = position;
//bt01点击
holder.bt01.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View v) {
}
});
//bt02点击
holder.bt02.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View v) {
}
});
//bt03点击
holder.bt03.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View v) {
}
});
return convertView;
}
class ViewHolder {
Button bt01;
Button bt02;
Button bt03;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询