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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:48:39+00:00 2026-05-28T15:48:39+00:00

My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items

  • 0

My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items in my database correctly. it does not display the text in the TextView, what else do I have to do to the cursor for it to show the correct text?

I thought I had to override the bindView but that had no effect

Setting the adapter:

public void populateList(){

        String[] fields = new String[] {BowlersDB.NAME};
        Cursor c = getActivity().getContentResolver().query(BowlersDB.CONTENT_URI,
                new String[] {BowlersDB.ID,BowlersDB.NAME},null,null,BowlersDB.NAME + " COLLATE LOCALIZED ASC");

mAdapter = new CheckAdapter(getActivity(),R.layout.check_listview,c,fields,new int[] {R.id.nameCheckTV});


        setListAdapter(mAdapter);   

        getLoaderManager().initLoader(0,null,this);
    }

Adapter:

public class CheckAdapter extends SimpleCursorAdapter{

    Context context;
    Cursor c;

    public CheckAdapter(Context context, int layout, Cursor c,String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.context = context;
        this.c = c;
        // TODO Auto-generated constructor stub
    }

    @Override
    public void bindView(View view,Context context,Cursor cursor){
        String st = cursor.getString(cursor.getColumnIndex(BowlersDB.NAME));

        TextView tv = (TextView)view.findViewById(R.id.nameCheckTV);
        tv.setText(st);
    }

    @Override
    public View getView(final int position,View convertView,ViewGroup parent){
        if(convertView == null){
            LayoutInflater inflator = getLayoutInflater();
            convertView = inflator.inflate(R.layout.check_listview,null);
        }

        CheckBox cb = (CheckBox)convertView.findViewById(R.id.checkBox1);   
            cb.setOnClickListener(new OnClickListener(){

                @Override
                public void onClick(View v) {
                    CheckBox check = (CheckBox)v.findViewById(R.id.checkBox1);
                    int pos = position;
                    if(check.isChecked()){
                        mCheckedItems.add(position);
                    }else if(!check.isChecked()){
                        for(int i=0;i< mCheckedItems.size();i++){
                            if(mCheckedItems.get(i) == position){
                                mCheckedItems.remove(i);
                            }
                        }
                    }
                }

            });
        return convertView;
    }

}
  • 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-28T15:48:40+00:00Added an answer on May 28, 2026 at 3:48 pm

    I think I got it. Check out the implementation for CursorAdapter.getView(). Notice how bindView() and newView() are called within getView(). It looks like by overriding getView() you are ensuring that your CursorAdapter never calls bindView(). Either put everything ONLY in getView() or ONLY in newView() and bindView(), but not both.


    EDIT I:

    Four things:

    1. I’ve read up on CursorAdapters and it looks like you want to override bindView() instead of getView(). It looks like getView() is called twice for each row that’s to be displayed and this is somehow preventing the cursor from being updated and thus always points to the first row. I think this is why your ListView only displays the first row. Further, the default CursorAdapter implementation for a ListView will recycle views for you, so overriding getView() really isn’t necessary (check out this answer for more info).

    2. When creating your mAdapter, you should pass a null Cursor into the constructor. The Cursor will be delivered in onLoadFinished (when the Loader has finished the query) and will be bound to the adapter with swapCursor(cursor).

    3. Your onCreateLoader() method will create (or start) the Loader that will perform the initial query. Make sure it looks something like this,

      @Override
      public Loader<Cursor> onCreateLoader(int id, Bundle args) {
          String[] projection = { BowlersDB.ID, BowlersDB.NAME };
      
          CursorLoader cursorLoader = new CursorLoader(getActivity(),
                  BowlersDB.CONTENT_URI, projection, null, null, null);
          return cursorLoader;
      }
      
    4. Make sure you make use of the correct SimpleCursorAdapter constructor… the one you are currently using is deprecated! (pass 0as a flag… the CursorLoader will register a content observer for you so you don’t need to pass in anything special).


    EDIT II:

    To clarify, the bindView() method is where you populate your row’s widgets with the data from the Cursor‘s current position. You are handed the Cursor pre-positioned at the proper row. You need to pull data out of the Cursor and pour it into your desired widgets. In other words, you’ll need to query for the row’s id (instead of using the “position” argument in getView()). Try setting the onClickListener in bindView() with something like:

    final int rowId = cursor.getInt(cursor.getColumnIndex("_id"));
    
    CheckBox cb = (CheckBox)convertView.findViewById(R.id.checkBox1);   
    cb.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = rowId;
            /* you now know this row's position. do what you need to do. */
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I'm trying to delete items from a ListView using a custom adapter which extends
Custom map is broken on satellite view, does not show satellite imagery. Any ideas,
Embedded custom-tag in dynamic content (nested tag) not rendering. I have a page that
I am trying to create a list view which as TextView that can display
I have a custom list adapter: class ResultsListAdapter extends ArrayAdapter<RecordItem> { in the overridden
I am using a custom List adapter to display a list of all contacts,
I am creating a Spinner instance that I bind to my own custom adapter
I have List of items. I'm using custom adapter (Android 1.5). Everything works perfectly,

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.