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

  • Home
  • SEARCH
  • 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 6755777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:26:36+00:00 2026-05-26T13:26:36+00:00

When I run my activity that has the list view I am trying to

  • 0

When I run my activity that has the list view I am trying to populate, it shows as empty. However, in logcat I can see that the custom CursorAdapter runs through my data and returns at least some views.

    public class JobAdapter extends CursorAdapter {

private String status;
private static final String tag ="TESTING CursorAdapter";

public JobAdapter(Context context, Cursor cur, boolean autoRequery, String s) {
    super(context, cur, autoRequery);
    Log.d(tag, "Job adapter create");
    status = s;
}

@Override
public void bindView(View row, Context context, Cursor cursor) {
    Log.d(tag, "Starting a bind");
    Cursor c = getCursor();
    if(!c.isClosed()){  
        TextView companyName = (TextView) row.findViewById(R.id.listCompanyName);
        TextView positionTitle = (TextView) row.findViewById(R.id.listPositionTitle);


        while(!c.isLast() && !c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
            Log.d(tag, "bind - moving c to next 1");
            c.moveToNext();
        }

        if(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
            Log.d(tag, "found a status and trying to populate the view");
            companyName.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_COMPANY)));
            positionTitle.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_POSITION)));

            Log.d(tag, "Company name = "+c.getString(c.getColumnIndex(JobsDbAdapter.KEY_COMPANY)));

            if(c.isLast()) {
                Log.d(tag, "bind - Closing c 1");
                c.close();
            }else {
                Log.d(tag, "bind - moving c to next 2");
                c.moveToNext();
            }
         }
    }
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    Cursor c = getCursor();
    Log.d(tag, "Starting a new");
    final LayoutInflater inflater = LayoutInflater.from(context);
    View row = inflater.inflate(R.layout.job_list_item, parent, false);

    if(!c.isClosed()){  
        TextView companyName = (TextView) row.findViewById(R.id.listCompanyName);
        TextView positionTitle = (TextView) row.findViewById(R.id.listPositionTitle);

        while(!c.isLast() && !c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
            Log.d(tag, "new - moving c to next 1");
            c.moveToNext();
        }

        if(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_STATUS)).equalsIgnoreCase(status)){
            Log.d(tag, "new - found a status and trying to populate the view");
            companyName.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_COMPANY)));
            positionTitle.setText(c.getString(c.getColumnIndex(JobsDbAdapter.KEY_POSITION)));

            if(c.isLast()) {
                Log.d(tag, "new - Closing c 1");
                c.close();
            }else {
                Log.d(tag, "new - moving c to next 2");
                c.moveToNext();
            }

    }
    Log.d(tag, "new - returning row");
    return row;
}

}

Should I be checking to see if the cursor has reached the end of the database ? Or will this be handled for me ?

My class that uses this adapter is simply

    public class AppliedForActivity extends ListActivity {

private JobsDbAdapter mDbHelper;

public void onCreate(Bundle savedInstanceState) {
    Log.d("TESTING C", "STARTING THE APPLIED FOR ACTIVITY");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.job_list);
    mDbHelper = new JobsDbAdapter(this);
    mDbHelper.open();
    Cursor c = mDbHelper.fetchAllJobs();
    setListAdapter(new JobAdapter(this, c, false, "applied for"));
}

}

Please excuse the curly braces, I may have copied wrong.

  • 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-26T13:26:37+00:00Added an answer on May 26, 2026 at 1:26 pm

    The idea of CursorAdapter is to incapsulate all the postioning from your code and to leave only visualizing to you. That is you need not use moveToNext and other positioning methods.

    As I can see in your code you are trying to implement some filtering. But the idea of working with database is to formulate your criteria in SQL query. Instead of querying ALL the jobs you should select only those which should be displayed in the ListView.

    bindView and newView should only work with current record the cursor is pointed to and should never call moveToNext or close. Also, CursorAdapter assumes your cursor has an integer field named ‘_id’.

    See also here and there.

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

Sidebar

Related Questions

I am trying to setup an activity in Android that has 50% of the
I am trying to run a system call which will post an activity to
Im trying to make a countdown timer run in the background of my activity,
I want to create a service that has a onWindowFocusChanged method, native to Activity.
I have an activity that I can declare as Launcher category and it launches
My launch activity extends ListActivity and uses a layout that has a listview and
I have a Switch activity that has an expression of escalateEngine.CheckRules() Where escalateEngine is
We have a SQL 2000 server that has widely varied jobs that run at
Possible Duplicate: How can I get device ID for Admob My activity has a
Hey, Im trying something in android, that has to get the words sent in

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.