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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:50:58+00:00 2026-06-14T02:50:58+00:00

I am using cursoradapter to get the values from database and to display it

  • 0

I am using cursoradapter to get the values from database and to display it in listview.I am able to show the database contents in listview also onclick of perticular item I am getting value of clicked Item.Now I want checkbox also so that oncheck I should get the values of checked Items ( In this case both checkbox click and listitemclick both should work) is it possible? how to do it?

private void displayListView() {
        final Cursor cursor = dbHelper.fetchAllRecords();
        String[] columns = new String[] {
                RecordsDbAdapter.KEY_NAME,
                RecordsDbAdapter.KEY_BIRTHDAY,

        };
        int[] to = new int[] {
                R.id.name,
                R.id.birthdate,
        };
        dataAdapter = new SimpleCursorAdapter(
                this, R.layout.rownew,
                cursor,
                columns,    
                to);
        View v = getLayoutInflater().inflate(R.layout.customdialog, null);
        ListView listView = (ListView) v.findViewById(R.id.listChildren);
        final EditText etChild = (EditText) v.findViewById(R.id.etChild);
        listView.setAdapter(dataAdapter);
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                name = ((TextView) view.findViewById(R.id.name)) .getText().toString();
                BirtDate = ((TextView) view.findViewById(R.id.birthdate)) .getText().toString();
                Log.d("*************", name);

                Info=name+ " " +BirtDate;
                Log.d("nameeeeeeeeeeeeeeee",Info);
                etChild.setText(new StringBuilder().append(Info));
                topaste=etChild.getText().toString();
                    etChild.setText(new StringBuilder().append(Info1));
                //                  topaste1=etChild.getText().toString();
                //              }


            }
        })

My rownew.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="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="#FFFFFF"
    android:gravity="center"
    android:padding="6dp" >

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:id="@+id/birthdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="@string/text"
        android:textStyle="bold" >
    </TextView>


</LinearLayout>

My Customdialog.xml

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

    <EditText
        android:id="@+id/etChild"
         android:hint=""
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >
    </EditText>

    <ListView
        android:id="@+id/listChildren"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF" >
    </ListView>
  </LinearLayout>
  • 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-14T02:50:59+00:00Added an answer on June 14, 2026 at 2:50 am

    You could extend SimpleCursorAdapter to add a click listener for your checkbox. Here is a snippet of the code I use:

    public class MultiSelectCursorAdapter extends SimpleCursorAdapter {
    
      public MultiSelectCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
            super(context, layout, c, from, to, flags);
        }
    
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
        final int fposition = position;
        View view = super.getView(position, convertView, parent);
        CheckBox checkbox = (CheckBox) view.findViewById(R.id.list_checkbox);
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d("CHECKER", "Something happened: " + fposition + " was clicked " + isChecked);
                // TODO: store id of checked items in your model
                }
    
        });
    
        return view;
        }
    }
    

    In your list row layout you need to set android:focusable="false" in order to allow clicks on list items and clicks on the checkbox of each list item.

    <CheckBox
            android:id="@+id/list_checkbox"
            android:focusable="false" 
            ... >
    </CheckBox>
    

    Finally you need a model or data structure to store all checked items of your list, e.g. an array or list that stores identifiers for all checked items.

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

Sidebar

Related Questions

Say my application has a ListView that displays information from a Sqlite database, using
I have a ListView which is populated using a CursorAdapter. I'd also like to
Using the Redis info command, I am able to get all the stats of
I'm trying to fill a listview with a database query. I'm using a custom
i have a listview with checkbox in each rows. i'm using custom cursoradapter and
I'm trying to populate a ListView with data from a query using a CursorLoader.
I am using a listview with section headers as in this example. http://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ The
I'm using a SimpleCursorAdapter and a ListView to show some data loaded with a
I'm using 3 AutocompleteTextViews to suggest entries from a database. I subclassed AutocompleteTextView to
I am using a CursorAdapter in a ListFragment to load and display a list

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.