Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to set a onclicklistener for button inside the listview in android?
    text
    copied!<p>I have a listView having a button and a textView. How can I set onclicklistener for the button inside the listView? Code Given below:</p> <p>ListView.xml:</p> <pre><code>ListView lv1 = (ListView)popupView.findViewById(R.id.listView1); listviewAdapter adapter = new listviewAdapter(Order_page.this, alist); lv1.setAdapter(adapter); </code></pre> <p>ListviewAdapter Class is as follows:</p> <pre><code>public class listviewAdapter extends BaseAdapter { public ArrayList&lt;HashMap&lt;String, String&gt;&gt; list; Activity activity; public listviewAdapter(Activity activity, ArrayList&lt;HashMap&lt;String, String&gt;&gt; list) { super(); this.activity = activity; this.list = list; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } class ViewHolder { Button btn_fav, btn_plus, btn_minus; TextView item_name; TextView item_price; TextView item_total; EditText et_quantity; } @Override public View getView(int position, View convertView, final ViewGroup parent) { // TODO Auto-generated method stub // TODO Auto-generated method stub ViewHolder holder; LayoutInflater inflater = activity.getLayoutInflater(); if (convertView == null) { convertView = inflater.inflate(R.layout.order_list_texts, null); holder = new ViewHolder(); holder.btn_fav = (Button) convertView.findViewById(R.id.fav_btn_orderlist); holder.btn_plus = (Button) convertView.findViewById(R.id.order_pg_plus); holder.btn_minus = (Button) convertView.findViewById(R.id.order_pg_minus); holder.item_name = (TextView) convertView.findViewById(R.id.item_name); holder.item_price = (TextView) convertView.findViewById(R.id.itm_price); holder.item_total = (TextView) convertView.findViewById(R.id.Item_total); holder.et_quantity = (EditText) convertView.findViewById(R.id.et_quantity_order_list); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } HashMap&lt;String, String&gt; map = list.get(position); holder.item_name.setText(map.get(ITEM_NAME_COLUMN)); holder.item_price.setText(map.get(ITEM_PRICE_COLUMN)); holder.item_total.setText(map.get(TOTAL_COLUMN)); holder.et_quantity.setText(map.get(ITEM_QUANTITY_COLUMN)); return convertView; } } </code></pre> <p>Please help to set onClick event of the button</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload