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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:22:49+00:00 2026-05-23T16:22:49+00:00

I have an adapter that extends simplecursoradapter. The new view is supposed to take

  • 0

I have an adapter that extends simplecursoradapter. The new view is supposed to take a cursor from a database along with an image, populate a list with a couple of checkboxes. For some reason I can’t seem to see, my getView is not even being called. I have a breakpoint inside getView and it never gets there and the list just shows up empty.
Can anyone take a look thru and see what I’ve done wrong

public class TakeStudentAttendance extends ListActivity {
private gradeBookDbAdapter mDbHelper;
private Long mRowId;
private TextView mNameText;
private String classname;
private Boolean new_attendance = false;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Cursor stud;

    mDbHelper = new gradeBookDbAdapter(this);
    mDbHelper.open();
    mRowId = (savedInstanceState == null) ? null
            : (Long) savedInstanceState
                    .getSerializable(gradeBookDbAdapter.KEY_ROWID);
    if (mRowId == null) {
        Bundle extras = getIntent().getExtras();
        mRowId = extras != null ? extras
                .getLong(gradeBookDbAdapter.KEY_ROWID) : null;
    }
    // pull in class data
    stud = mDbHelper.fetchClass(mRowId);
    startManagingCursor(stud);

    classname = stud.getString(
                stud.getColumnIndexOrThrow(gradeBookDbAdapter.KEY_CLASSNAME));
    String title = "Attendance for " + classname;
    setTitle(title);

    setContentView(R.layout.attendance_list);
    Button doneButton = (Button) findViewById(R.id.Done);
    doneButton.setOnClickListener(mAttendanceActivity);

    // check previous attendance date
    String prevdate = stud.getString(
            stud.getColumnIndexOrThrow(gradeBookDbAdapter.KEY_PREVDATE));

    stud = mDbHelper.fetchAttendanceByClass(mRowId);  // this query yields _id, name, 
                                                      // attend, late, dtime

    if (mDbHelper.getClassDate() == prevdate){
        // previous date is the same, so we're doing attendance again: retain values
        new_attendance = false;
    }
    else {
        // dates are different, so we're starting from scratch and all students are
        // absent until counted present. I just need names and will populate attendance
        new_attendance = true;          
        // upon attendance start-up, NO ONE is present. Set all entries in DB to not present (0)
        setNoAttend(stud, mRowId);
        // reset cursor position
        stud.moveToFirst();
    }



    // Create an array to specify the fields we want to display in the list 
    String[] from = new String[]{gradeBookDbAdapter.KEY_NAME,
                                 gradeBookDbAdapter.KEY_ROWID,
                                 gradeBookDbAdapter.KEY_ATTEND,
                                 gradeBookDbAdapter.KEY_LATE,
                                 gradeBookDbAdapter.KEY_DTIME};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.stuname, 
                         R.id.stuIndex,
                         R.id.attend,
                         R.id.late,
                         R.id.stuIndex};

    // Now create a simple cursor adapter and set it to display
    // mRowId holds the class index.
    MyDataAdapter studs = 
       new MyDataAdapter(this, R.layout.show_attendance, stud, from, to, mRowId, new_attendance);
    setListAdapter(studs);
} 

Here’s my adapter code:

public class MyDataAdapter extends SimpleCursorAdapter {
private Cursor c;
private Context context;
private Long classnum;
private gradeBookDbAdapter mDbHelper;
private Boolean newValues;
private ArrayList<String> list = new ArrayList<String>();
private ArrayList<Boolean> itemCheckedHere = new ArrayList<Boolean>();
private ArrayList<Boolean> itemCheckedLate = new ArrayList<Boolean>();
private ArrayList<Integer> itemCheckedIdx = new ArrayList<Integer>();
int idxCol;
int idx;

// itemChecked will store the position of the checked items.

public MyDataAdapter(Context context, int layout, Cursor c, String[] from,
        int[] to, Long mRowId, Boolean new_attendance) {
    super(context, layout, c, from, to);
    this.c = c;
    this.context = context;
    mDbHelper = new gradeBookDbAdapter(context);
    mDbHelper.open();
    classnum = mRowId;
    newValues = new_attendance;
    c.moveToFirst();
    for (int i = 0; i < c.getCount(); i++) {
        itemCheckedHere.add(i, false); // initializes all items value with false
        itemCheckedLate.add(i, false); // initializes all items value with false
    }
}

public View getView(final int pos, View inView, ViewGroup parent) {
    File file;
    ImageView studentPhoto;

    if (inView == null) {
               LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inView = inflater.inflate(R.layout.show_attendance, null);
    }

    // set up name field        
    final TextView studentName = (TextView) inView.findViewById(R.id.stuname); 
    final TextView studentIndex = (TextView) inView.findViewById(R.id.stuIndex);
        if (studentName != null)
        {
            c.moveToPosition(pos);
            int index = c.getColumnIndex(gradeBookDbAdapter.KEY_NAME);
            String name = c.getString(index);
            studentName.setText(name);

            index = c.getColumnIndex(gradeBookDbAdapter.KEY_STUDENT);
            String Index = c.getString(index);
            studentIndex.setText(Index);


             // set up photo icon

            file = new File(Environment.getExternalStorageDirectory () + 
                      "/gradeBook/" + name + ".jpg");
            studentPhoto = (ImageView) inView.findViewById(R.id.icon);

            if (file.exists()) {
                String fileName = file.getAbsolutePath();
                BitmapFactory.Options opts = new BitmapFactory.Options();
                Bitmap bm;

                bm = BitmapFactory.decodeFile(fileName, opts);
                studentPhoto.setImageBitmap(bm);
            } 
            else {
                // use icon image
                studentPhoto.setImageResource(R.drawable.person_icon);
            }

    } 
    final CheckBox cBoxH = (CheckBox) inView.findViewById(R.id.attend);
    final CheckBox cBoxL = (CheckBox) inView.findViewById(R.id.late);


    cBoxH.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            CheckBox cb = (CheckBox) v.findViewById(R.id.attend);

            if (cb.isChecked()) {
                itemCheckedHere.set(pos, true); 
                int Index = new Integer(studentIndex.getText().toString());
                mDbHelper.insertAttend(Index, classnum,  1 ); 
            } else if (!cb.isChecked()) {
                itemCheckedHere.set(pos, false);
                int Index = new Integer(studentIndex.getText().toString());
                mDbHelper.deleteAttend(Index, classnum );
            }
        }
    });
    cBoxL.setOnClickListener(new OnClickListener() {

       public void onClick(View v) {
            CheckBox cb = (CheckBox) v.findViewById(R.id.late);

            if (cb.isChecked()) {
               itemCheckedLate.set(pos, true);
               // do some operations here
            } else if (!cb.isChecked()) {
               itemCheckedLate.set(pos, false);
               // do some operations here
            }
        }
    });
    cBoxH.setChecked(itemCheckedHere.get(pos)); // this will Check or Uncheck the
    cBoxL.setChecked(itemCheckedLate.get(pos)); // this will Check or Uncheck the
    // CheckBox in ListView
    // according to their original
    // position and CheckBox never
    // loss his State when you
    // Scroll the List Items.
    return inView;
}

}
  • 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-23T16:22:50+00:00Added an answer on May 23, 2026 at 4:22 pm

    This got answered in the comment, but it might as well get a real answer ^^

    getCount() is actually returning 0, so the problem is in the query coming back empty, and not in the adapter.

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

Sidebar

Related Questions

I have an adapter that uses a CheckedTextView and extends from a SimpleCursorAdapter .
OK, so I have a cursor adapter that I cobbled together from various source
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items
I have a main activity that takes elements from a database and displays them
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have a list adapter that handles objects with some image and text and
I have created a new class called Get_WebPage1 and init I have extends that
I have an app that will query a database and attempt to output results
I have a activity that extends listactivity, extended in this class i have a

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.