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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:24:52+00:00 2026-06-15T23:24:52+00:00

I override SimpleAdapter: class NoticelistAdapter extends SimpleAdapter { public NoticelistAdapter(Context context, List<? extends Map<String,

  • 0

I override SimpleAdapter:

class NoticelistAdapter extends SimpleAdapter
 {
    public NoticelistAdapter(Context context,
            List<? extends Map<String, ?>> data, int resource,
            String[] from, int[] to)
    {
        super(context, data, resource, from, to);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        Map<String,Object> map= list.get(position);
        int readState =  (Integer) map.get("ReadState");
        if (readState == 1)
        {
            // do something to change the color of title
        }
        return convertView;
    }
 }

And the adapter is:

adapter = new NoticelistAdapter(NoticelistActivity.this, list, R.layout.row_noticelist,
                                    new String[] { "Title", "RealName","Date"}, 
                                    new int[] { R.id.noticetitle, R.id.noticerealname,R.id.noticedate});

There is an int parameter in each map called “readstate”, if the readstate == 1, then I want change the color of “Title” (TextView) to another color.
I know I should override getView(…) in my adapter, but I dont know how to do this. Will you please help me. Thank you in advance.

  • 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-15T23:24:54+00:00Added an answer on June 15, 2026 at 11:24 pm

    Override the Adapter’s getItemViewType() to return two different layout flags, and override getViewTypeCount() to return the number of views. Then depending on flag, set the row layout in getView():

     private static final int TYPE_READ = 0;
     private static final int TYPE_NON_READ = 1;
     private static final int TYPE_MAX_COUNT = TYPE_NON_READ + 1;
     //...
    
        @Override
        public int getItemViewType(int position) {
             int readState =  (Integer) mMap.get("ReadState");
            if(readState==1){
               return TYPE_READ;
            }else{
               return TYPE_NON_READ;
            }
    
        @Override
        public int getViewTypeCount() {
            return TYPE_MAX_COUNT;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            int type = getItemViewType(position);
    
            if (convertView == null) {
                holder = new ViewHolder();
                switch (type) {
                    case TYPE_READ:
                        convertView = mInflater.inflate(R.layout.item_one, null);
                        //set read layout
                        break;
                    case TYPE_NON_READ:
                        convertView = mInflater.inflate(R.layout.item_two, null);
                        // set non-read layout
                        break;
                }
        //etc
    

    Here is a complete tutorial.

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

Sidebar

Related Questions

public class ABC extends ListActivity { static final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); @Override
Ok, now this is my SimpleAdapter's getView function: @Override public View getView(int position, View
I have a class that extends ListActivity with a SimpleAdapter as the list adapter.
public class BabyNamesActivity extends ListActivity { public ArrayList<HashMap<String, String>> List1, List2, List3; public ListView
I have a: public class MyList extends ListActivity { SimpleAdapter simpleAdapter; Binding to the
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); savedInstanceState.putString(foo, bar); } @Override public void
@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); // providers data // db.execSQL(insert into //
im trying to override the add() but it will not compile public class AVLTree<E
@Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Integer createUsers(final Collection<MyUser> myUsers) { final
I have a main class filled with a cursor adapter: public class MainMenu extends

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.