Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:27:22+00:00 2026-06-16T03:27:22+00:00

I have a listView having a button and a textView. How can I set

  • 0

I have a listView having a button and a textView. How can I set onclicklistener for the button inside the listView?
Code Given below:

ListView.xml:

ListView lv1 = (ListView)popupView.findViewById(R.id.listView1);
listviewAdapter adapter = new listviewAdapter(Order_page.this, alist);
lv1.setAdapter(adapter);

ListviewAdapter Class is as follows:

public class listviewAdapter extends BaseAdapter {
public ArrayList<HashMap<String, String>> list;
Activity activity;

public listviewAdapter(Activity activity,
        ArrayList<HashMap<String, String>> 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<String, String> 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;
}

}

Please help to set onClick event of the button

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:27:23+00:00Added an answer on June 16, 2026 at 3:27 am

    completed code am listed below its too simple.

    public class listviewAdapter extends BaseAdapter {
    public ArrayList<HashMap<String, String>> list;
    Activity activity;
    
    public listviewAdapter(Activity activity,
            ArrayList<HashMap<String, String>> 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, btn_delete;
        TextView item_name;
        TextView item_price;
        TextView item_total;
        EditText et_quantity;
    
    }
    
    @Override
    public View getView(final int position, View convertView,
            final ViewGroup parent) {
        // TODO Auto-generated method stub
    
        final 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.orderlist_plus);
            holder.btn_minus = (Button) convertView.findViewById(R.id.orderlist_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);
    
            holder.btn_delete = (Button) convertView.findViewById(R.id.btn_order_list_delete);
    
            convertView.setTag(holder);
    
        } 
        else 
        {
            holder = (ViewHolder) convertView.getTag();
        }
    
        final HashMap<String, String> 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));
    
        holder.btn_delete.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
    
                list.remove(position);
                notifyDataSetChanged();
                //Log.v("sd", "" + alist);
    
            }
        });
    
        holder.btn_minus.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
    
                //to get a specific item
                Toast.makeText(activity,"" + holder.item_name.getText().toString(),Toast.LENGTH_LONG).show();
    
            }
        });
    
        /*
         * holder.et_quantity.addTextChangedListener(new TextWatcher() {
         * 
         * @Override public void onTextChanged(CharSequence arg0, int arg1, int
         * arg2, int arg3) { // TODO Auto-generated method stub
         * 
         * }
         * 
         * @Override public void beforeTextChanged(CharSequence arg0, int arg1,
         * int arg2, int arg3) { // TODO Auto-generated method stub
         * 
         * }
         * 
         * @Override public void afterTextChanged(Editable arg0) { // TODO
         * Auto-generated method stub Toast.makeText(activity,
         * ""+getItem(position), 1000).show(); } });
         */
        return convertView;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listview having customized some textview and one imageview. When I long click
I have a listview with custom row having a textview and a clickable image
I am having trouble with a scrolling ListView inside a ScrollView . I have
I have a user control which is having a listview inside it. The SelectionChanged
I have a query that selects rows in a ListView without having a limit.
I am having a bit of a strange issue. I have a ListView which
i have to show 3 columns in List view. I tried having table inside
I am having problems with ListView on android. I have an Activity with an
I have a nested GridView that is placed inside a ListView. The GridView renders
What I have: I have a ListView with custom rows, having a CheckBox &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.