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

  • Home
  • SEARCH
  • 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 7917765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:15:38+00:00 2026-06-03T15:15:38+00:00

i want to create listview like below. check box | Textview | Textview |

  • 0

i want to create listview like below.

check box | Textview | Textview | Textview | Textview | Textview | Textview |

all data come from database and set in textview.

i tried but i got some problem

  1. when i select checkbox and scroll list then its automaticaly uncheked.

  2. if i select first check box then 5th is automaticaly checked.

  3. check all & un-check all

please help me i tried many code but i am not success.

thanks in advance.

  • 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-03T15:15:40+00:00Added an answer on June 3, 2026 at 3:15 pm

    it may help you.

    package com.Sample_MultipleSelection;
    
    import java.util.ArrayList;
    
    import android.R.integer;
    import android.app.Activity;
    import android.app.ListActivity;
    import android.content.Context;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.Toast;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    import android.widget.TextView;
    
    public class Sample_MultipleSelectionActivity extends ListActivity {
    
        private MyListAdapter adapter;
        ArrayList<String> item_id = new ArrayList<String>();
        ArrayList<String> item_name = new ArrayList<String>();
        ArrayList<String> item_balance = new ArrayList<String>();
        ArrayList<String> item_email = new ArrayList<String>();
    
        ArrayList<String> items = new ArrayList<String>();
    
        private CheckBox chk_main;
        boolean flag = false;
        boolean[] selection;
        ArrayList<String> selection_val;
        private Button btn_select;
        private CheckBox chk_select;
        ViewHolder holder12;
        boolean select_all;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
    
            item_id.add("1");
            item_name.add("China");
            item_balance.add("4000");
            item_email.add("china@gmail.com");
    
            item_id.add("2");
            item_name.add("abc");
            item_balance.add("4000");
            item_email.add("abca@gmail.com");
    
            item_id.add("3");
            item_name.add("xyz");
            item_balance.add("4000");
            item_email.add("xyz@gmail.com");
    
            item_id.add("4");
            item_name.add("xyza");
            item_balance.add("40070");
            item_email.add("xyze@gmail.com");
    
            item_id.add("5");
            item_name.add("xyzc");
            item_balance.add("1000");
            item_email.add("xyz123@gmail.com");
    
            final ViewHolder holder = new ViewHolder();
            selection = new boolean[item_id.size()];
            selection_val = new ArrayList<String>();
    
            adapter = new MyListAdapter(this);
            setListAdapter(adapter);
    
            holder12 = new ViewHolder();
    
    
            btn_select = (Button) findViewById(R.id.button1);
            btn_select.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
    
                    int len = selection.length;
                    int cnt = 0;
                    String selectIds = "";
                    for (int i = 0; i < len; i++) {
                        if (selection[i]) {
                            cnt++;
                        }
                    }
                    for (int i = 0; i < selection_val.size(); i++) {
                        selectIds = selectIds + " | " + selection_val.get(i);
                    }
                    if (cnt == 0) {
                        Toast.makeText(getApplicationContext(), "NO Selection", 1)
                                .show();
                    } else {
                        Toast.makeText(
                                getApplicationContext(),
                                "Your are Selected   " + cnt + " ids. " + " "
                                        + selectIds, 1).show();
                    }
                }
            });
        }
    
        public class MyListAdapter extends BaseAdapter {
            Context con;
            private LayoutInflater layoutinf;
            ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
            ArrayList<String> items_ = new ArrayList<String>();
    
            public MyListAdapter(
                    Sample_MultipleSelectionActivity sample_MultipleSelectionActivity) {
                con = sample_MultipleSelectionActivity;
            }
    
            public int getCount() {
                return item_id.size();
            }
    
            public Object getItem(int arg0) {
                return item_id.size();
            }
    
            public long getItemId(int arg0) {
                return item_id.get(arg0).hashCode();
            }
    
            public View getView(final int arg0, View arg1, ViewGroup arg2) {
    
                View v = arg1;
                ViewHolder holder = null;
                if (v == null) {
                    layoutinf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = layoutinf.inflate(R.layout.row, null);
                    holder = new ViewHolder();
                    holder.chk = (CheckBox) v.findViewById(R.id.checkBox1);
                    holder.tv_name = (TextView) v.findViewById(R.id.textView1);
                    holder.tv_bal = (TextView) v.findViewById(R.id.textView2);
                    holder.tv_email = (TextView) v.findViewById(R.id.textView3);
    
                    v.setTag(holder);
                } else {
                    holder = (ViewHolder) v.getTag();
                }
    
                holder.chk.setId(arg0);
                holder.tv_name.setId(arg0);
    
                holder.chk.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
    
                        try {
                            CheckBox cb = (CheckBox) v;
                            int id = cb.getId();
                            String val = cb.getText().toString();
                            if (selection[id]) {
                                cb.setChecked(false);
                                selection[id] = false;
                                selection_val.remove("" + val);
                            } else {
                                cb.setChecked(true);
                                selection[id] = true;
                                selection_val.add("" + val);
                            }
                            adapter.notifyDataSetChanged();
                        } catch (Exception e) {
                            Log.e("error", "" + e.toString());
                        }
                    }
                });
                holder.chk.setChecked(selection[arg0]);
    
                if(selection[arg0] == true)
                {
                    holder.tv_name.setBackgroundColor(Color.GRAY);
                    holder.tv_bal.setBackgroundColor(Color.GRAY);
                    holder.tv_email.setBackgroundColor(Color.GRAY);
                }
                else
                {
                    holder.tv_name.setBackgroundColor(Color.TRANSPARENT);
                    holder.tv_bal.setBackgroundColor(Color.TRANSPARENT);
                    holder.tv_email.setBackgroundColor(Color.TRANSPARENT);
                }
    
                holder.chk.setText(item_id.get(arg0));
                holder.tv_name.setText("" + item_name.get(arg0));
                holder.tv_bal.setText(item_balance.get(arg0));
                holder.tv_email.setText(item_email.get(arg0));
    
                return v;
            }
        }
    
        public class ViewHolder {
            private CheckBox chk;
            private TextView tv_name;
            private TextView tv_bal;
            private TextView tv_email;
    
        }
    }
    

    main.xml

     <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <CheckBox
                android:id="@+id/chk_main"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
    
                android:text="" />
    
            <TextView
                android:id="@+id/textView1"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Name"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#66cc33" />
    
            <TextView
                android:id="@+id/textView2"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Balance"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#66cc33" />
    
            <TextView
                android:id="@+id/textView3"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Email-Id"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#66cc33" />
        </LinearLayout>
    
        <View
            android:id="@+id/view1"
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:background="#fff" />
    
        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="314dp"
            android:layout_weight="1" >
        </ListView>
    
        <Button
            android:id="@+id/button1"
            android:focusable="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="select" />
    
        </LinearLayout>
    

    row.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:orientation="horizontal">
    
    
                             <CheckBox
                                android:id="@+id/checkBox1"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"                            
                                android:textColor="#000" />
    
    
    
                            <TextView
                                android:id="@+id/textView1"
                                android:layout_width="100dp"
                                android:layout_height="wrap_content"                         
                                 android:padding="3dp"
                                android:textAppearance="?android:attr/textAppearanceMedium" />
    
                            <TextView
                                android:padding="3dp"
                                android:id="@+id/textView2"
                                android:layout_width="100dp"
                                android:layout_height="wrap_content"                         
                                android:textAppearance="?android:attr/textAppearanceMedium" />
    
                            <TextView
                                android:padding="3dp"
                                android:id="@+id/textView3"
                                android:layout_width="100dp"
                                android:layout_height="wrap_content"                         
                                android:textAppearance="?android:attr/textAppearanceMedium" />
    
        </LinearLayout>
    

    make it right it if it correct.

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

Sidebar

Related Questions

I want to create custom AlertDialog, but without AlertDialog.Builder. I set ListView as content
ASP.Net 3.5 I want to create a user control that contains the ListView and
i want to create horizontal list with these uielements in wpf.I already use listview
I just want ask for your comments/suggestions on how to create a customized listview
For clarification : I want all the custom dialogs to look like system default
I have a following problem. I have a ListView which returns data from SQL
I want to create the activity which will load the images from Web by
Hey, I want to know how do I do to create a ListView in
Hey I want to create a layout like this for my application. Of course
I want to create a simple ProgressDialog in my Activity. I created it like

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.