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 6356269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:55:52+00:00 2026-05-24T22:55:52+00:00

my app has custom ListView, each row contains checkbox ,edit text and 2 buttons.

  • 0

my app has custom ListView, each row contains checkbox ,edit text and 2 buttons. In the main xml layout file i have 1 submit button and listView. i want that, when i click on submit button, i should get all checked row position.I am new to android programming ,so plz help me my code is not working here is my code:

main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button android:layout_height="wrap_content" 
android:text="@string/button_submit" 
android:layout_width="wrap_content" 
android:id="@+id/main_submit_button" android:onClick="@string/button_submit"></Button>

<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

items.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">


<LinearLayout android:layout_height="wrap_content"
  android:layout_width="fill_parent">

  <TextView 
  android:layout_height="wrap_content"
  android:layout_width="fill_parent" android:layout_weight="1"
  android:id="@+id/items_name" 
  android:gravity="left"
  android:textStyle="bold" />

  <CheckBox android:id="@+id/items_check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right"
         />

</LinearLayout>


 <LinearLayout android:layout_height="wrap_content"
  android:layout_width="fill_parent">

  <Button android:id="@+id/items_add_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:gravity="left"
    android:text="@string/text_switcher_plus" />

   <EditText android:digits="10" 
   android:textStyle="bold" android:gravity="left" 
   android:id="@+id/items_plates" android:layout_height="wrap_content" 
   android:layout_width="90dp"></EditText>


  <Button  android:layout_height="wrap_content"         
    android:layout_width="wrap_content"  
    android:id="@+id/items_minus_button"
    android:text="@string/text_switcher_minus"
    android:gravity="right"
    />


     </LinearLayout>

 </LinearLayout>

VegmenuActivity

package com.sagar.resmenu;

import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

  // reference:http://pareshnmayani.wordpress.com/tag/android-custom-listview-example
  public class VegmenuActivity extends Activity implements OnItemClickListener{

 //dynamic array that contains names of items
   private ArrayList<String> items = new ArrayList<String>
   (Arrays.asList("Veg pulav", "Pav bhaji", "Panir tikka", "veg kolhapuri",
           "Coconut Rice", "Curd rice", "Mint Pulao",
                         "Banana  Custard","Basundi", "Cheese potato Tikkis",
                          "Dum aloo"));

   private ArrayList<Integer> counter = new ArrayList<Integer>
                        (Arrays.asList(0, 0,0, 0, 0,0, 0,0, 0,0,0));

   private SparseBooleanArray a;

   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    final ListView lv =(ListView)findViewById(R.id.list_view);
  //  lv.setOnClickListener(null);
    MyAdapter adapter = new MyAdapter(getApplicationContext(),items,counter);
    lv.setAdapter(adapter);
    lv.setItemsCanFocus(false);    
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    Button submit1;
    submit1 = (Button)findViewById(R.id.main_submit_button);
    submit1.setOnClickListener(new OnClickListener()
    {
    @Override
    public void onClick(View v)
    {
        a = new SparseBooleanArray();
        a.clear();
        a = lv.getCheckedItemPositions();
        int len = items.size();

        for (int i = 0; i < len; i++)
        {


            if(a.valueAt(i) == true)
                Log.d("Returned ", String.valueOf(a.valueAt(i)));

         }                
      }
    }); 

   }    

  //private OnItemClickListener selectCat = new OnItemClickListener();
   public void onItemClick(AdapterView<?> a, View v, int positon, long id) {
    // TODO Auto-generated method stub
          } 

  }

MyAdapter.java

 package com.sagar.resmenu;

 import java.util.ArrayList;

 import android.content.Context;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.View.OnClickListener;
 import android.widget.BaseAdapter;
 import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.EditText;
 import android.widget.TextSwitcher;
 import android.widget.TextView;

public class MyAdapter extends BaseAdapter implements OnClickListener{
  private LayoutInflater inflater;
  private ArrayList<String>  data;
  VegmenuActivity m;
  private ArrayList<Integer> counter;

 public MyAdapter(Context context, ArrayList<String> data,ArrayList<Integer> counter) {
    // TODO Auto-generated constructor stub
   super();
  // Caches the LayoutInflater for quicker use
   this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  // Sets the events data
   this.data= data;
  this.counter=counter;   
  }


 public int getCount() {
    return this.data.size();
//return this.counter.size();
  }

  public String getItem(int position) throws IndexOutOfBoundsException{
    return null;
  }

  public long getItemId(int position) throws IndexOutOfBoundsException{
    return 0;
  }

  public int getViewTypeCount(){
    return 1;
  }

  public static class ViewHolder   
    { 


        TextView items_name;

        CheckBox items_check ;
        Button items_plus_button;
        Button items_minus_button;
        EditText plates;
    }


  public View getView(int position, View convertView, ViewGroup parent){
     //String myText = getItem(position);          
     ViewHolder holder;
     if(convertView == null){ // If the View is not cached
        // Inflates the Common View from XML file
         holder = new ViewHolder();
        convertView = this.inflater.inflate(R.layout.items,parent,false);

        holder.items_name = (TextView) convertView.findViewById(R.id.items_name);
        holder.plates = (EditText) convertView.findViewById(R.id.items_plates);
        holder.items_check = (CheckBox) convertView.findViewById(R.id.items_check);      

       convertView.setTag(holder);

                }

                else           
                 holder=(ViewHolder)convertView.getTag();       

                 holder.items_name.setText(data.get(position));
                 holder.plates.setText(String.valueOf(counter.get(position)));
                return convertView;
     }    

 @Override
 public void onClick(View arg0) {
    // TODO Auto-generated method stub

 }  

 }
  • 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-05-24T22:55:53+00:00Added an answer on May 24, 2026 at 10:55 pm

    when I need check boxes inside listview, I often code as following:

    MyAdapter.java:
    
    - Declare an boolean array to mark which item is checked/unchecked:
    
        ....
        boolean[] checked;
        ...
    
    inside constructor: 
    
        checked = new boolean[data.size()];
    
    - Inside getView() 
    
        {
    
    
       .....
    
        holder.items_check.setChecked(checked[position]);
        holder.items_check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked[position] = isChecked;              
          }
        });
        .....
    - And method to get all checked items:
    boolean[] getCheckedItems() {
       return checked;
    }
    

    That’s !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an app that implements a custom ListView that contains images.
I am developing an app which has a list view with custom layout as
My iPhone App has custom buttons that display png-images. I like to replace the
My app has a custom object that contains an NSDate. I want to change
We've got a WinForms app written in C# that has a very custom GUI.
I am creating a custom membership provider for a web app that already has
My app has several buttons which trigger different events. The user should NOT be
My app has three text fields: 1) Username // Initialization code usernameTextField = [[UITextField
I have an app that has a custom background for a UITableView . Up
Our app has a UITableViewController with some custom section headers. These section headers are

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.