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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:20:31+00:00 2026-06-01T00:20:31+00:00

I’m still not getting exactly how a custom CursorAdapter should work, so after hard

  • 0

I’m still not getting exactly how a custom CursorAdapter should work, so after hard tries, here is the thing :

  1. I implement a listener on a button inside my getView().
  2. The listener launches a delete row event.
  3. To get to it, I use a singleton database where I can perform request from all classes (The purpose of a singleton actually)
  4. I usually update (insert and modify) from the activity class, so I just have to get the new database cursor and re-assign it to a new CursorAdapter, that I re-assign itself to the ListView.
  5. Here it’s different : I’m inside the CursorAdapter class in the ListView method, and I don’t know how to update my adapter from the inside.

For people who don’t want to read my boring explanations, here is the code of the getView :

    @Override
public View getView(int position, View convertView, ViewGroup parent){
    convertViewParam = convertView;
    ViewHolder viewHolder = new ViewHolder();
    if (convertViewParam == null) {
        int type = getItemViewType(position);
        switch (type) {

        case TYPE_ADD_NOTE_TOP:
            convertViewParam = inflater.inflate(R.layout.add_note_top, null);
            viewHolder.contentNote = (EditText)convertViewParam.findViewById(R.id.add_note_top_id);
            break;
        case TYPE_ITEM:
            convertViewParam = inflater.inflate(R.layout.row_note, null);
            viewHolder.delete = (Button)convertViewParam.findViewById(R.id.delete);
            if (deleteMode){
                viewHolder.delete.setVisibility(View.VISIBLE);
            }else{
                viewHolder.delete.setVisibility(View.GONE);
            }

            viewHolder.contentNote = (TextView)convertViewParam.findViewById(R.id.note);

            getCursor().moveToPosition(position - 1);
            int currentPosition = getCursor().getPosition();
            Cursor c = getCursor();
            c.moveToPosition(currentPosition);

            ((TextView) viewHolder.contentNote).setText(c.getString(c.getColumnIndex("content_note")));
            int rowId = c.getInt(c.getColumnIndex("_id"));

            viewHolder.delete.setTag(new Integer(rowId));
            viewHolder.contentNote.setTag(new Integer(rowId));

            OnClickListener listener = new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int thePosition = (Integer) v.getTag();

                    int posCurs = notesCursorAdapter.getCursor().getPosition();
                    NoteDataSource.getSingletonObject(context).deleteNote(thePosition, context);
                    notesCursorAdapter.changeCursor(NoteDataSource.getSingletonObject(context).getAllNotes());
                    notesCursorAdapter.notifyDataSetChanged();

                }
            };
            viewHolder.delete.setOnClickListener(listener);

            break;

        case TYPE_ADD_NOTE_BOTTOM:
            convertViewParam = inflater.inflate(R.layout.add_note_bottom, null);
            LinearLayout linearLayout = (LinearLayout)convertViewParam.findViewById(R.id.bottomLayout);
            linearLayout.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
            break;
        }
        convertViewParam.setTag(viewHolder);
    } else {

        viewHolder = (ViewHolder)convertViewParam.getTag();
        if (viewHolder.contentNote!=null){
            if (viewHolder.contentNote.getTag() == convertViewParam.findViewById(R.id.note)){
                int test = (Integer) viewHolder.delete.getTag();
                System.out.println("current tag " + test);
                String txt = getCursor().getString(getCursor().getColumnIndex("content_note"));
                ((TextView) viewHolder.contentNote).setText(txt);
            }
        }


    }

    return convertViewParam;
}

I get the following error when I launch the delete event:

03-28 17:51:32.996: E/AndroidRuntime(7115): android.database.CursorIndexOutOfBoundsException: Index 2 requested, with a size of 2

If you want more info ask.

I’m looking for a bug fix or an just explanation, thanks.

  • 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-01T00:20:33+00:00Added an answer on June 1, 2026 at 12:20 am

    Thats a very well written problem statement. I have had this problem and broke my head over it. Try this.

    • In your Adapter make a listener, something like
    public interface ItemDeletedListener(){
        public void itemDeleted(int position);
    }
    
    • create an instance of ItemDeletedListener in your adapter, m_listener.

    • Write a setter function, setItemDeletedListener( ItemDeletedListener listener){}

    • In your getView(), onClickListener, call m_listener and pass the position that needs to be deleted.

    Now in your Activity, Do the following.

    1. Implement the listener, that you created above.
    2. In your implementation, do the deletion work and then do a changeCursor() there.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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 string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
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 have just tried to save a simple *.rtf file with some websites 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.