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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:55:10+00:00 2026-05-17T17:55:10+00:00

i have been having this issue for some time now, and have not gotten

  • 0

i have been having this issue for some time now, and have not gotten an answer for it yet. i have this custom Cursor adapter which i use to populate a list view from an sqlite database. Now my issue is that i want to populate the listview based on certain conditions.An example is if the condition is important, the listview should display only data that fits into that criteria and so on. I already have working methods that query the database accordingly.

now my problem is that, i can’t seem to populate the listviews based on those methods and conditions without:

1) creating a copy of the exact same custom cursor adapter and just changing the names variables.
2) creating a copy of the exact xml layout and changing the id’s.

As i say, its working this way, but i feel am having unnecessary classes and xml layout since its exactly the same thing. I know am doing something wrong, i just don’t know what. Please any help and explanation would be appreciated. here is the necessary part of the code Code for the CustomCursorAdapter:

 public class ViewItems extends ListActivity implements OnItemClickListener{

     DBAdapter adapter;
     Cursor cursor;
     ListView list;

     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.view_list);
      adapter = new DBAdapter(this);
      adapter.open();
      fillData();

      list = (ListView)findViewById(android.R.id.list); // default android listView id
      list.setOnItemClickListener(this);


     }

     // Different method calls
     protected void fillImportantData() {
      Cursor cursor = adapter.retrieveImportant();
      startManagingCursor(cursor);

        String[] from = new String[]{DBAdapter.NAME, DBAdapter.DATE, DBAdapter.TIME, DBAdapter.PRIORITY};
        int[] to = new int[]{R.id.viewNameId, R.id.viewDateId, R.id.viewTimeId};

        customCursorAdapter items = new customCursorAdapter(this, R.layout.view_items, cursor, from, to);
        setListAdapter(items);   
     }



     public class customCursorAdapter extends SimpleCursorAdapter {
      private int layout;
      Context context;

      public customCursorAdapter(Context context, int layout, Cursor cursor, String[]from, int[] to) {
       super(context, layout, cursor, from, to);
       this.layout = layout;
       this.context = context;

      }


      @Override
      public void bindView(View view, Context context, Cursor cursor) {
       ViewHolder holder;

       if(view != null){
        holder = new ViewHolder();
        holder.viewName = (TextView)view.findViewById(R.id.viewNameId);
        holder.viewStartDate = (TextView)view.findViewById(R.id.viewDateId);
        holder.viewStartTime = (TextView)view.findViewById(R.id.viewTimeId);

        view.setTag(holder);
       }else{
        holder = (ViewHolder)view.getTag();
       }

       int namecol = cursor.getColumnIndex(DBAdapter.NAME); 
       String name = cursor.getString(namecol);


       if(holder.viewName != null){
       holder.viewName.setText(name);
       holder.viewName.setTextColor(Color.RED);
       }

       String startDate = cursor.getString(cursor.getColumnIndex(DBAdapter.DATE));
       holder.viewStartDate.setText(startDate);

       String startTime = cursor.getString(cursor.getColumnIndex(DBAdapter.TIME));
       holder.viewStartTime.setText(startTime);
      }


      @Override
      public View newView(Context context, Cursor cursor, ViewGroup parent) {

       LayoutInflater inflater = LayoutInflater.from(context);
       final View view = inflater.inflate(layout, parent, false);

       return view;
      }


     @Override
      public long getItemId(int id){
       return id;
      }


    @Override
      public Object getItem(int position){
       return position;
      }

     }

     static class ViewHolder{
      TextView viewName;
      TextView viewStartDate;
      TextView viewStartTime;

     }

    }


// methods in database

public Cursor retrieveAll(){
  String[] resultColumns = new String[] {KEY_ID, NAME DATE, TIME, PRIORITY};
    Cursor cursor = db.query(DATABASE_TABLE, resultColumns, null, , null, null, null);
     return cursor; 
    }

public Cursor retrieveImportant(){
  String[] resultColumns = new String[] {KEY_ID, NAME DATE, TIME, PRIORITY};
  String[] condition = {"important"};
  Cursor cursor = db.query(DATABASE_TABLE, resultColumns, PRIORITY + "=" + "?", condition, null, null, null);
     return cursor; 
    }
  • 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-17T17:55:10+00:00Added an answer on May 17, 2026 at 5:55 pm
    1. If you change the data you wish to display, you will need to run a fresh query on the database and get a Cursor back that reflects that changed data. Depending on the nature of the changes, this may require a fresh CursorAdapter or merely a call to changeCursor(). If the new query returns the same columns and you want them displayed the same way, changeCursor() is probably sufficient. Otherwise, you will need to create a new CursorAdapter and call setAdapter() on your ListView to switch over to it.

    2. You only need a different row layout if you are truly changing the row layout. You do not need to change IDs just for grins. Since you are not doing this in the code you have shown above, I am unclear what specifically you are worried about.

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

Sidebar

Related Questions

I have been having this issue for a while now and I cannot seem
For a long time I've been having this issue that at a certain time
This problem has been bothering me for sometime now, I have not settled on
This is a really weird problem that I have been having. When I download
I have been trying to tackle this problem , but I am having difficulty
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I have been having some problems trying to get my PHP running. When I
We've been working with a Subversion repository for some time now for a research
I have been working for some time on a library which performs numeric calculations.
UPDATE I am still debugging this issue and still have not found a solution.

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.