Android listView 中响应Button点击事件

其实很简单就是在getView中给button添加接口
public class Task_list_single_item_adapter extends BaseAdapter { LayoutInflater inflater; Context context; public Task_list_single_item_adapter(Context context){ this.context=context; inflater=LayoutInflater.from(context); } @Override public int getCount() { return 2; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; dedecms.com } @Override public View getView(int position, View convertView, ViewGroup parent) { final Holder holder; if(convertView!=null) { holder=(Holder) convertView.getTag(); }else { holder=new Holder(); convertView=inflater.inflate(R.layout.download_management_item, null); holder.pause=(Button) convertView.findViewById(R.id.dmi_ib1_pause); holder.trys=(Button) convertView.findViewById(R.id.dmi_ib2_recover); holder.install=(Button) convertView.findViewById(R.id.dmi_ib3_install); convertView.setTag(holder); } OnClickListener listener=new OnClickListener(){ @Override public void onClick(View v) { if(v==holder.pause){ Toast.makeText(context, "pause", Toast.LENGTH_SHORT).show(); dedecms.com holder.pause.setVisibility(View.GONE); holder.trys.setVisibility(View.VISIBLE); holder.install.setVisibility(View.GONE); } if(v==holder.trys){ Toast.makeText(context, "try", Toast.LENGTH_SHORT).show(); holder.pause.setVisibility(View.VISIBLE); holder.trys.setVisibility(View.GONE); holder.install.setVisibility(View.GONE); } if(v==holder.install) Toast.makeText(context, "install", Toast.LENGTH_SHORT).show(); } }; holder.pause.setOnClickListener(listener); holder.trys.setOnClickListener(listener); holder.install.setOnClickListener(listener); return convertView; } class Holder{ public Button pause; dedecms.com public Button trys; public Button install; } } public class Task_list_single_item_adapter extends BaseAdapter { LayoutInflater inflater; Context context; public Task_list_single_item_adapter(Context context){ this.context=context; inflater=LayoutInflater.from(context); } @Override public int getCount() { return 2; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { final Holder holder; if(convertView!=null) { holder=(Holder) convertView.getTag(); }else { holder=new Holder(); convertView=inflater.inflate(R.layout.download_management_item, null); holder.pause=(Button) convertView.findViewById(R.id.dmi_ib1_pause); holder.trys=(Button) convertView.findViewById(R.id.dmi_ib2_recover); 织梦内容管理系统 holder.install=(Button) convertView.findViewById(R.id.dmi_ib3_install); convertView.setTag(holder); } OnClickListener listener=new OnClickListener(){ @Override public void onClick(View v) { if(v==holder.pause){ Toast.makeText(context, "pause", Toast.LENGTH_SHORT).show(); holder.pause.setVisibility(View.GONE); holder.trys.setVisibility(View.VISIBLE); holder.install.setVisibility(View.GONE); } if(v==holder.trys){ Toast.makeText(context, "try", Toast.LENGTH_SHORT).show(); holder.pause.setVisibility(View.VISIBLE); holder.trys.setVisibility(View.GONE); holder.install.setVisibility(View.GONE); } if(v==holder.install) Toast.makeText(context, "install", Toast.LENGTH_SHORT).show(); } }; holder.pause.setOnClickListener(listener); holder.trys.setOnClickListener(listener); holder.install.setOnClickListener(listener); return convertView; } class Holder{ public Button pause; public Button trys; public Button install; } }

你可能感兴趣的:(android,list,ListView,null,Class,button)