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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:36:12+00:00 2026-05-16T15:36:12+00:00

I have a listview that needs to be multiple choice (i.e each list item

  • 0

I have a listview that needs to be multiple choice (i.e each list item has a checkbox which can be checked / unchecked)
The list view is in a tabhost and is the content for teh first tab.

My set up is like so:

My tab is set up with:

TabSpec tab = tabHost.newTabSpec("Services");

tabHost.addTab(tabHost.newTabSpec("tab_test1").setIndicator("Services").setContent(new Intent(this, ServiceList.class)));

When the tab is clicked new activity ServiceList is started

ServiceList is defined as such:

    public class ServiceList extends ListActivity{
        private EscarApplication application;
        ListView listView;
         @Override
           public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.service_list);
             ServiceList.this.application = (EscarApplication) this.getApplication();
             final ListView listView = getListView();
         }

         protected void onListItemClick(ListView l, View v, int position, long id) {
            String.valueOf(id);
            Long.toString(id);
            ((CheckedTextView) v).setChecked(true);
            super.onListItemClick(l, v, position, id);
        }

         @Override
         public void onStart() {
             super.onStart();
            //Generate and display the List of visits for this day by calling the AsyncTask
             GenerateServiceList services = new GenerateServiceList();
             int id = ServiceList.this.application.getVisitId();
             services.execute(id);
             listView  = getListView();
             listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
         }

        //The AsyncTask to generate a list
         private class GenerateServiceList extends AsyncTask<Integer, String, Cursor> {
              // can use UI thread here
              protected void onPreExecute() {
              }
              // automatically done on worker thread (separate from UI thread)
              protected Cursor doInBackground(Integer...params) {
                  int client_id = params[0];
                  ServiceList.this.application.getServicesHelper().open();
                  Cursor cur = ServiceList.this.application.getServicesHelper().getPotentialVisitServices(client_id);
                  return cur; 

              }
              // can use UI thread here
              protected void onPostExecute(Cursor cur){  
                  startManagingCursor(cur);
                  // the desired columns to be bound
                  String[] columns = new String[] {ServicesAdapter.KEY_SERVICE};
                  // the XML defined views which the data will be bound to
                  int[] to = new int[] {R.id.display_service};
                  SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(ServiceList.this, R.layout.service_list_element, cur, columns, to);
                  // set this adapter as your ListActivity's adapter
                  ServiceList.this.setListAdapter(mAdapter);
ServiceList.this.application.getServicesHelper().close();       

              }
         }
    }

So, everything works ok until I click on my list item to change the checkbox state.

The part of teh code set to handle click events is causing me problems:

 protected void onListItemClick(ListView l, View v, int position, long id) {
                String.valueOf(id);
                Long.toString(id);
                ((CheckedTextView) v).setChecked(true);
                super.onListItemClick(l, v, position, id);
            }

My understanding is that the View v passed to the onListItemClick method reperesents my list element, so I am trying to cast v as a CheckedTextView and set teh checked value to true, however this just causes my app to crash. Am I missing something simple here, or is there an easier way to do this?

Thanks

Kevin

  • 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-16T15:36:13+00:00Added an answer on May 16, 2026 at 3:36 pm

    Have you debugged it to check if ‘v’ is null? If so, you need to use a layoutInflator to retrieve the view.

    if(v == null)
    {
        LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.service_list, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that contains button on each item. I want that the
I have seen examples of ListView where each row has multiple view objects, like
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have a ListView that has a custom ArrayAdapter with a custom XML row.
I have a ListView in Android that needs to have the ability to be
I have a ListView with a checkbox field inside that gets the id set
I have a ListView which displays multiple rows of ListViewItems. The user is able
I have a ListView that displays a link button. I need the link button
I have ListView that uses a GridView to display several columns of data. Two
I have a ListView that shows around 300 items. When something is changed and

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.