Listview With Button Android Studio Example

Hello, In this listview with button android tutorial, you will learn how to use a button in listview item and how to handle it clicks listeners.

First of all check out the output of this example, so that you can have an idea what we are developing at the end of the tutorial.

Wait for one minute

If you have not basic idea about listview and adapter, check out listview with image and text tutorial first.

Check listview with checkbox android example for gaining knowledge about how to use a checkbox in listview row.

How to get maximum benefit from Listview with button android tutorial

Download Source Code

Try Our App

Download DemoNuts app to learn anytime, anywhere: Click to get Demonuts App

Or search “demonuts” in play store from android mobile device.

Creating Listview With Button Android Example

If you are using adblocker, then you will not be able to show our site smoothly. For example, you find step 6 after step 1 or similar to this. So please disable adblocker to fully utilize all resources of DemoNuts

Step 1: Create a new project in the android studio.

Step 2: Updating activity_main.xml file

Add following code into activity_main.xml file

Step 3: Creating class

Create a new class named and add following

Step 4: Creating Integer Resource File

In this tutorial, we need to create integer resources.

Integer resources are same as string resources which are written at string.xml file in values directory.

To define integer resources, we need to create integer.xml file in values directory.

To create integer.xml file, right click on values folder -> New -> Value resource file

listview with button android integer

Directory for integer.xml

Copy following code in an integer.xml file

Step 5: Creating row layout for listview

Create one layout resource file and name it as lv_item.xml and copy below code

Step 6: Creating class:

Create new java class named CustomAdapter and add following code

Step 7: Setting tag for position and convertView

Look at this code

When listview is populating, we can set tags for postion and views as per above code.

We have set tags on btn_plus for position and converView.

setTag(key,value) method is used for this.

key for tag is used from the integer.xml file, we created earlier.

Your key should be unique for setting each tag.

Step 8: Getting tags in buttons onClick() method

You can get position and converView by using getTag(key) method.

We are setting tempview with view got from getTag() method.

In getTag() method we are using same key, which we used in setTag() method.

Similarly we can get position also using getTag() method and proper key.

Here tempview is a whole row view which contains two textView and two button.

You can inflate views of row view and set values to them. Here we are setting textView’s value by following code

Similarly, for btn_minus, all tags are set and get and values of textView are updated.

Step 9: Creating NextActivity

To open new activity in android studio, click on File tab which is present at the left top bar.

Now go to File->New->Activity->Empty Activity and give name of activity as NextActivity.

listview with button android next activity

Step 10: Updating NextActivtiy code

Add following code into activity_next.xml 

Add following into class

Step 11: Updating class

Put below code in

How to get exact Android example while searching in Google

Click to get Important Google searching tips

So it was all about implementing listview with button android feature in our android app programmatically. Thank you and keep coding ?

  1. andy
    • Hardik Parsania
  2. Wiley
    • Hardik Parsania
  3. Nikhil agarwal

Leave a Reply

Your email address will not be published. Required fields are marked *