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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:31:28+00:00 2026-05-26T14:31:28+00:00

I have an Activity (not a ListActivity, although I should probably convert my code

  • 0

I have an Activity (not a ListActivity, although I should probably convert my code into one since it’s only displaying a ListView). In this ListView I have a setup a layout for the rows, and it contains two TextView and one CheckBox. The Layout is shared by another Activity, so I have set CheckBox.visibility="GONE" so the activities can enable them on their own if they need the checkboxes.

I have a SimpleCursorAdapter for my ListView. In this adapter I override setViewValue() so I can enable the checkbox, like this:

adapter = new SimpleCursorAdapter(this, R.layout.location_browser_listview_relative, cursor, FROM, TO);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
  @Override
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    if (view.getId() == R.id.checkBox) {
      // Enable the star-checkbox
      ldb.isFavourite(cursor.getInt(cursor.getColumnIndex(LocationDB.C_ID)));
      view.setVisibility(View.VISIBLE);
      ((TextView)view).setText("");
      return true;
    }

    return false;
  } // setViewValue
}); // setViewBinder

furthermore I have setup an onClickListener() because the user is supposed to click a list element (a whole row). The listener goes like this:

listItems.setOnItemClickListener(new OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    final int numItems = cursor.getInt(cursor.getColumnIndex(LocationDB.C_NUM_ITEMS));
    String foo = String.format(TAG + "Clicked: %d", numItems);
    Log.i(LOG_TAG, foo);

    AlertDialog.Builder dialog = new AlertDialog.Builder(StoreBrowser.this);
    dialog.setMessage("Vill du bevaka?");
    dialog.setPositiveButton("Ja", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        // TODO: Save to DB here
        System.out.println("Hello from onClick");

        ldb.addFavourite(ID);
      }
    }); // setPositiveButton         

    dialog.setNegativeButton("Nej", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(getApplicationContext(), "Clicked no", Toast.LENGTH_SHORT).show();
      }
    }); // setNegativeButton         

    dialog.show();
  } // onItemClick
}); // setOnItemClickListener

Questions:

  1. In setViewValue(), the code ldb.isFavourite() is issued three times according to Logcat (I use Log.d() in the method). Why is it called three times? There’s a SQL-query running in it, and I suspect it will be quite expensive running it three times for each listview row.

2a. How can I intercept a click on the checkbox? I need to toggle a boolean variable when the user toggles the checkbox. The onClick() only fires when the user clicks the whole listview row, but when the checkbox is clicked nothing happens.

2b. Is there a way to collect all checkbox info at the same time instead of toggling a boolean when user clicks? I mean, when the user is done selecting, is there a way to go through all the listelements one by one in a loop and fetch the click-value?

Bonus question: I suspect I should rewrite this code and manually inflate the listview and its elements, so if anyone can point me to a good resource describing this kind of work I’d be grateful. Google’s API-docs aren’t very helpful.

  • 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-26T14:31:29+00:00Added an answer on May 26, 2026 at 2:31 pm

    @ 1. How many rows does your cursor iterate over? – I suspect it might be 3.

    @ 2b. Not quite sure about the ListView, but have a look at ViewGroup.getChildAt() to iterate through the ListView‘s children and at View.findViewById() to locate your desired child view inside each child of the ListView.

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

Sidebar

Related Questions

my class extends Activity, not ListActivity. i have this code on create method but
Note that my activity is NOT extending ListActivity; just Activity. I have a list
My current application has one Activity, the main one which extends ListActivity (listview of
I have JavaScript that is doing activity periodically. When the user is not looking
I have Activity with ListView inside it and in the onCreate method of the
I have an Activity in Android, with two elements: EditText ListView When my Activity
I have a layout that creates a ListActivity. Before displaying the ListActivity, I perform
Android:How to display images from the web in a ListView?I have the following code
I have a activity that extends listactivity, extended in this class i have a
I have a service bound to an activity. The activity is a ListView of

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.