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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:12:14+00:00 2026-06-08T17:12:14+00:00

I’m using a custom list adapter for my ListView. How can I get the

  • 0

I’m using a custom list adapter for my ListView. How can I get the database rowid/_id from the checked checkbox so that I can multiple delete the data from my database?

Here’s my activity:

import android.app.ListActivity;
import java.text.DecimalFormat;
import org.yhw.PlanWithMe.R;
import android.content.*;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.database.Cursor;

public class Finance_delete extends ListActivity {
    Cursor cursor;
    private TextView dateText;
    private Button btnCancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.finance_delete);

        registerForContextMenu(this.getListView());
        DBAdapter dbHelper = new DBAdapter(this);
        dbHelper.open();

        // Get a Cursor for the list items
        Intent intent = getIntent();
        String date = intent.getStringExtra("date");
        Cursor listCursor = dbHelper.getAllFinance(date);
        startManagingCursor(listCursor);

        // set the custom list adapter
        setListAdapter(new MyListAdapter(this, listCursor));

        dateText = (TextView) findViewById(R.id.lblDate);
        dateText.setText("Delete Spending: " + date);

        btnCancel = (Button) findViewById(R.id.btnCancel);
        btnCancel.setOnClickListener(click_listener);
    }

    private class MyListAdapter extends ResourceCursorAdapter {

        public MyListAdapter(Context context, Cursor cursor) {
            super(context, R.layout.list_item_with_description_delete, cursor);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {

            CheckBox cbListCheck = (CheckBox) view
                    .findViewById(R.id.list_checkbox);
            cbListCheck.setChecked(false);

            cbListCheck
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {
                        public void onCheckedChanged(CompoundButton cb,
                                boolean isChecked) {
                            if (cb.isChecked()) {
                                // action


                            } else if (isChecked == false) {
                                // action

                            }
                        }
                    });

            TextView title = (TextView) view.findViewById(R.id.list_category);
            title.setText(cursor.getString(cursor
                    .getColumnIndex(DBAdapter.KEY_Category)));

            TextView details = (TextView) view.findViewById(R.id.list_desc);
            StringBuffer detailsText = new StringBuffer();

            String description = cursor.getString(cursor
                    .getColumnIndex(DBAdapter.KEY_Desc));

            TextView spendings = (TextView) view
                    .findViewById(R.id.list_spending);

            String spending = cursor.getString(cursor
                    .getColumnIndex(DBAdapter.KEY_Spending));

            double tgtspend = Double.parseDouble(spending);
            DecimalFormat dFormat = new DecimalFormat("0.00");
            String formatSpend = dFormat.format(tgtspend);
            spendings.setText("$" + formatSpend);

            if (description != null && description.length() > 0) {
                detailsText.append(description);
            } else {
                detailsText.append("-");
            }
            details.setText(detailsText.toString());

        }
    }

    private OnClickListener click_listener = new OnClickListener() {
        public void onClick(View view) {
            // Intent intent = null;
            switch (view.getId()) {
            case R.id.btnCancel:
                finish();
                break;
            }
        }
    };
}

My Activity layout:

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/finance_top" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="45dp"
        android:src="@drawable/navbar" />

    <TextView
        android:id="@+id/lblDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="57dp"
        android:layout_alignParentLeft="true"
        android:textColor="#ffffff"
        android:textSize="16dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="240dp"
        android:layout_marginTop="48dp"
        android:src="@drawable/divider" />

    <Button
        android:id="@+id/btnTick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="45dp"
        android:layout_marginTop="56dp"
        android:background="@drawable/btn_tick" />

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="6dp"
        android:layout_marginTop="56dp"
        android:background="@drawable/btn_cancel" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="282dp"
        android:layout_marginTop="48dp"
        android:src="@drawable/divider" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="92dp"
        android:orientation="vertical" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <TextView
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="106dp"
            android:layout_marginTop="180dp"
            android:text="@string/finance_note"
            android:textColor="#ffffff"
            android:textSize="18dp" />
    </LinearLayout>

</RelativeLayout>

My ListView layout:

<?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="?android:attr/listPreferredItemHeight" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:duplicateParentState="true" >

        <TextView
            android:id="@+id/list_category"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:gravity="center_vertical"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/list_desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/list_category"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/list_spending"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:gravity="center"
            android:paddingBottom="10dip"
            android:paddingTop="10dip"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <CheckBox
            android:id="@+id/list_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:text="" >
        </CheckBox>
    </RelativeLayout>

</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-08T17:12:15+00:00Added an answer on June 8, 2026 at 5:12 pm

    1) Link you checkbox with ID using checkbox.setTag property.

    2) In your delete button click event perform following logic.

    • Loop through all the checkboxes
    • collect the Id’s of those who are checked using checkbox.getTag attribute and collect it as comma separated.
    • use the comma separated values for delete operations.

    Hope you got the point and please check this link for conceptual implementations.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.