Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Why don't we use moveToFirst() in bindView?

When implementing onLoadFinished(), it requires moveToFirst() to work well, but why isn't this required when implementing bindView() for CursorAdapter? And when to use it?

onLoadFinished:

@Override
public void onLoadFinished(@NonNull Loader loader, Cursor data) {
    if (data.moveToFirst()) {
        int nameColumnIndex = data.getColumnIndexOrThrow(PetEntry.COLUMN_PET_NAME);
        int breedColumnIndex = data.getColumnIndexOrThrow(PetEntry.COLUMN_PET_BREED);

        mNameEditText.setText(data.getString(nameColumnIndex));
        mBreedEditText.setText(data.getString(breedColumnIndex));

    }
}

bindView:

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView name = view.findViewById(R.id.name);
    TextView summary = view.findViewById(R.id.summary);

    String nameString = cursor.getString(cursor.getColumnIndexOrThrow(PetEntry.COLUMN_PET_NAME));
    String summaryString = cursor.getString(cursor.getColumnIndexOrThrow(PetEntry.COLUMN_PET_BREED));

    name.setText(nameString);
    summary.setText(summaryString);
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The API explicitly states in CursorAdapter.bindView: @param cursor The cursor from which to get the data. The cursor is already moved to the correct position. So the moveToFirst is already done for you. The action is needed to advance in the records returned from the query on the database. If no records are found, moveToFirst will return false as per API description: Move the cursor to the first row. This method will return false if the cursor is empty.

The onLoadFinished isn't a member of the CursorAdapter and thus not tailored to do so.

Regards, Mike

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!