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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:05:04+00:00 2026-06-04T17:05:04+00:00

so im a little confused here…. i have code that takes info from my

  • 0

so im a little confused here….

i have code that takes info from my sqlite database and populates a list, then shows the list using the standard array adapter. what i want to do is have it so that in this list, the row color is green if the “completed” table row value is “yes”

heres my db structure for the table being used:

    String CREATE_ACHIEVEMENTS_TABLE = "CREATE TABLE achievements ("
             + "id INTEGER PRIMARY KEY,"
             + "name VARCHAR,"
             + "type VARCHAR,"
             + "value VARCHAR,"
             + "completed VARCHAR"
             + ")";

heres my code that gets the list from the db:

public ArrayList<String> getAchievements(Context context) {
    ArrayList<String> achievementList = new ArrayList<String>();
    String selectQuery = "SELECT * FROM achievements ORDER BY id asc";

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                if (cursor.getString(4).equals("yes")) {
                    achievementList.add(cursor.getString(1)+" (completed)");
                }
                else {
                    achievementList.add(cursor.getString(1));
                }
            } while (cursor.moveToNext());
        }
    }
    else {
        achievementList.add(context.getResources().getString(R.string.na));
    }

    cursor.close();
    db.close();
    return achievementList;
}

heres my custom arrayadapter:

public class AchievementAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final String[] values;

    public AchievementAdapter(Context context, String[] values) {
        super(context, R.layout.achievements, values);
        this.context = context;
        this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;

        if (row == null) {
            LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.achievement_item, parent, false);
        }

        return row;
    }
}

i really have no clue where to go from here. this is my first android app and i have learned a LOT, but i cant seem to figure out how to achieve this simple thing in regards to custom arrayadapters….all the tutorials i find contain a bunch of features that i dont want. all im trying to do is make the text color of the list item green if its “completed” table value is “yes”…

  • 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-04T17:05:05+00:00Added an answer on June 4, 2026 at 5:05 pm

    First of all, I recommend using a cursorAdapter instead of an arrayAdapter. With a cursor adapter you will have a pointer to the DB so you can get all of the information from there.

    If you do that… your code for the adapter should look something like this.

    private class MyCursorAdapter extends CursorAdapter {
    
        public MyCursorAdapter(Context context, Cursor c) {
            super(context, c);
        }
    
        @Override
        public void bindView(View v, Context context, Cursor cursor) {
            if(cursor.getString(cursor.getColumnIndex("completed").equals("yes")){
                TextView tv = (TextView) v.findViewById(R.id.NAMEOFTEXTVIEW);
                tv.setTextColor(Color.GREEN);
            }
        }
    
        @Override
        public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
            LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.achievement_item, parent, false);
            return row;
        }
    }
    

    and you create the adapter with:

    Cursor cursor = db.rawQuery(selectQuery, null);
    mAdapter = new MyCursorAdapter(this, cursor);
    

    Having said all that… if you want to use the arrayAdapter and just change the textview,
    in getView:

    String item = (String) getItem(position);
    if(item.contains("(completed)"){
        TextView tv = (TextView) row.findViewById(R.id.NAMEOFTEXTVIEW);
        tv.setTextColor(Color.GREEN);
    }
    

    I should note that with a cursorAdapter you should keep the cursor open, and close it in onStop (reopen it in onRestart)

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

Sidebar

Related Questions

I have a flaw in my code here and I am a little confused.
i'm a little bit confused here. i've PHP file that retrieve database records .
Just a little confused here... I have a function in postgres, and when I'm
OK, I am getting myself a little confused here. I have a WCF service
As always, i'm a little confused. Here https://community.jboss.org/wiki/ModularWebAppsWithJSF2 i've learned that it is easy
I'm a little confused here. I have my POCO classes created with the entity
I'm a little confused by the class code. Here's what I'm trying to do:
I feel I got a little confused here distinguishing sub-expression from expression. Compound expression
I'm a little bit confused here. I have 2 models: User Ticket A Ticket
I'm new to JQuery, so I'm a little confused here. I have a button

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.