Custom ListView

2

Well, I have a listview that loads data from a database. These data are numbers themselves, and I would like to be able to differentiate them. Type ... if the number is zero I would like it to be a specific color or bold. Or anything else that sets you apart from others that are not zero.

Does anyone know how to do it? Could you put an example here?

Thank you in advance!

    
asked by anonymous 23.05.2015 / 23:22

1 answer

3

You can do this by overwriting the method Adapter.html#getView in your adapter :

@Override
public View getView(int position, View convertView, ViewGroup parent) {  
   View view = super.getView(position, convertView, parent);
   TextView textView = (TextView) view.findViewById(R.id.text);
   String text = textView.getText().toString();

   if (text.equals("0")) {
       view.setBackgroundColor(Color.RED);
       //textView.setTypeface(null, Typeface.BOLD);
   } else {
       view.setBackgroundColor(Color.CYAN);  
   }

   return view;  
}

Source

    
23.05.2015 / 23:52