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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:54:04+00:00 2026-06-14T03:54:04+00:00

I have a listView with checkboxes, that use a cursor adapter. For some reason

  • 0

I have a listView with checkboxes, that use a cursor adapter. For some reason when I scroll the header (pageOrder==3) moves all over the place. It doesn’t stay on top. it will move around to position 13, 2, or 3. any ideas?

public class ExamCursorAdapter extends CursorAdapter {

private LayoutInflater inflater;
private int pageIndex;
private int pageTitleIndex;
private int pageOrderIndex;
private Context context;
private String assessmentId;

static class ViewHolder{
    protected TextView textViewTitle;
    protected TextView textViewHeader;
    protected TextView textViewCheckBox;
    protected CheckBox checkbox;
    protected int pageOrder;
    protected int pageId;
}

public ExamCursorAdapter(Context context, Cursor cursor, String assessmentId) {
    super(context, cursor, 0);
    this.context = context;
    this.assessmentId = assessmentId;
    pageIndex = cursor.getColumnIndex(PagesTable.COLUMN_ID);
    pageTitleIndex = cursor.getColumnIndex(PagesTable.COLUMN_TITLE);
    pageOrderIndex = cursor.getColumnIndex(PagesTable.COLUMN_ORDER);
    inflater = LayoutInflater.from(context);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder holder = (ViewHolder) view.getTag();
    holder.textViewTitle.setText(cursor.getString(pageTitleIndex)); 
    holder.pageOrder = cursor.getInt(pageOrderIndex);

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    ViewHolder holder = new ViewHolder();

    View view = null;
    holder.pageId = cursor.getInt(pageIndex);
    holder.pageOrder = cursor.getInt(pageOrderIndex);

    if(holder.pageOrder == 3) {
        view = inflater.inflate(R.layout.list_adapter_header_exam, null);
        holder.textViewTitle = (TextView) view.findViewById(R.id.adapter_header_textview_exam_column1);
        holder.textViewCheckBox = (TextView) view.findViewById(R.id.adapter_header_textview_exam_column2);
        holder.textViewCheckBox.setText("Complete");
        view.setFocusable(true);
    } else {
        view = inflater.inflate(R.layout.exam_row, null);
        holder.textViewTitle = (TextView) view.findViewById(R.id.exam_cursor_adapter_textview);
        holder.checkbox = (CheckBox) view.findViewById(R.id.exam_cursor_adapter_check_box);
        holder.checkbox.setClickable(false);    
        String[] projection = { ExamCompleteTable.COLUMN_EXAM_COMPLETE };
        StringBuilder sb = new StringBuilder();
        sb.append(BPContentProvider.EXAM_COMPLETE_URI).append("/assessment/").append(assessmentId);
        sb.append("/page/").append(holder.pageId);
        Uri examCompleteUri = Uri.parse(sb.toString());
        Cursor examCompleteCursor = context.getContentResolver().query(examCompleteUri, projection, null, null, null);
        if (examCompleteCursor.moveToFirst()) {
            int examComplete = examCompleteCursor.getInt(examCompleteCursor.getColumnIndexOrThrow(ExamCompleteTable.COLUMN_EXAM_COMPLETE));
            if(examComplete == 1) {
                holder.checkbox.setChecked(true);
            }
        } 
        examCompleteCursor.close();
    }
    view.setTag(holder);
    return view;
}


}
  • 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-14T03:54:05+00:00Added an answer on June 14, 2026 at 3:54 am

    Sounds like your are having trouble with the View recycler. Try letting the CursorAdapter know that there is more than one layout with these built-in methods:

    @Override
    public int getItemViewType(int position) {
        Cursor cursor = getCursor();
        cursor.moveToPosition(position);
        return (cursor.getInt(pageOrderIndex) == 3 ? 0 : 1);
    }
    
    @Override
    public int getViewTypeCount() {
        return 2;
    }
    

    Also this data looks like it changes depending on the content in each row:

    String[] projection = { ExamCompleteTable.COLUMN_EXAM_COMPLETE };
    StringBuilder sb = new StringBuilder();
    sb.append(BPContentProvider.EXAM_COMPLETE_URI).append("/assessment/").append(assessmentId);
    sb.append("/page/").append(holder.pageId);
    Uri examCompleteUri = Uri.parse(sb.toString());
    Cursor examCompleteCursor = context.getContentResolver().query(examCompleteUri, projection, null, null, null);
    if (examCompleteCursor.moveToFirst()) {
        int examComplete = examCompleteCursor.getInt(examCompleteCursor.getColumnIndexOrThrow(ExamCompleteTable.COLUMN_EXAM_COMPLETE));
        if(examComplete == 1) {
            holder.checkbox.setChecked(true);
        }
    } 
    examCompleteCursor.close();
    

    So this code needs to be in bindView() (or getView()) to change with the data in each row.

    As a tip, if examComplete stays constant while this Activity is in the foreground you can save these integers in a SparseIntArray or List<Integer> to speed things up.

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

Sidebar

Related Questions

For some reason if I have a listview that has checkboxes included it will
I have a ListView in a WPF Application that use Dynamic Binding . I
I have ListView with one column that contains checkboxes <ListView Height=164 HorizontalAlignment=Left ItemsSource={Binding ProductList}
i am use this for setting checkbox in listview i have follow all step
I have a ListView with multiple checkboxes (one for each list item). What would
I have listview having customized some textview and one imageview. When I long click
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have ListView that uses a GridView to display several columns of data. Two
I have ListView which is saving all data to database. For adding i have
I have a ListView that I'm populating with information from the media store. I

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.