怎么给list,view里面的BUtton设置点击事件
这样不可以吗privateSimpleAdaptersarr;privateList<Map<String,Object>>datalist;privateButtonb...
这样不可以吗
private SimpleAdapter sarr;
private List<Map<String,Object>>datalist;
private Button bt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bt1 =(Button)findViewById(R.id.anniu);
datalist= new ArrayList<Map<String,Object>>();
sarr =new SimpleAdapter(this, getData(), R.layout.demo, new String[]{"wenzi","tupian","anniu"}, new int []{R.id.wenzi,R.id.tupian,R.id.anniu});
setListAdapter(sarr);
bt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,FActivity.class);
startActivity(intent);
}
});
}//“wenzi”,“tupian” 后面对应id.wen,id.tupian, 有顺序
private List<Map<String,Object>> getData(){
Map<String,Object>map = new HashMap<String, Object>();
map.put("wenzi", "ss");
map.put("tupian", R.drawable.sucai13);
map.put("anniu", "点击了解详情");
datalist.add(map);
map =new HashMap<String, Object>();
map.put("wenzi", "欣");
map.put("tupian", R.drawable.sucai12);
map.put("anniu", "点击了解详情");
datalist.add(map);
map = new HashMap<String, Object>();
map.put("wenzi", "s");
map.put("tupian", R.drawable.sucai13);
map.put("anniu", "点击了解详情");
datalist.add(map);
map =new HashMap<String, Object>();
map.put("wenzi", "阿 ");
map.put("tupian", R.drawable.sucai12);
map.put("anniu", "点击了解详情");
datalist.add(map);
return datalist;
}
} 展开
private SimpleAdapter sarr;
private List<Map<String,Object>>datalist;
private Button bt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bt1 =(Button)findViewById(R.id.anniu);
datalist= new ArrayList<Map<String,Object>>();
sarr =new SimpleAdapter(this, getData(), R.layout.demo, new String[]{"wenzi","tupian","anniu"}, new int []{R.id.wenzi,R.id.tupian,R.id.anniu});
setListAdapter(sarr);
bt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,FActivity.class);
startActivity(intent);
}
});
}//“wenzi”,“tupian” 后面对应id.wen,id.tupian, 有顺序
private List<Map<String,Object>> getData(){
Map<String,Object>map = new HashMap<String, Object>();
map.put("wenzi", "ss");
map.put("tupian", R.drawable.sucai13);
map.put("anniu", "点击了解详情");
datalist.add(map);
map =new HashMap<String, Object>();
map.put("wenzi", "欣");
map.put("tupian", R.drawable.sucai12);
map.put("anniu", "点击了解详情");
datalist.add(map);
map = new HashMap<String, Object>();
map.put("wenzi", "s");
map.put("tupian", R.drawable.sucai13);
map.put("anniu", "点击了解详情");
datalist.add(map);
map =new HashMap<String, Object>();
map.put("wenzi", "阿 ");
map.put("tupian", R.drawable.sucai12);
map.put("anniu", "点击了解详情");
datalist.add(map);
return datalist;
}
} 展开
1个回答
推荐于2016-10-19
展开全部
需要自定义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;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询