Listview Customizado

Asked

Viewed 258 times

2

Guys, 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. Like... if the number is zero, I’d like it to be a specific color or bold. Or anything else that would differentiate you from others who are not zero.

Does anyone know how to do it? I could put an example here?

Thanks in advance!

  • 2

    Here’s a nice tutorial: http://www.androidhive.info/2014/android-custom-listview-with-image-and-textusing-volley/

  • Thank you for replying @Luídne. This tutorial is very good... but I want something that is different and at the same time common. Type: all fields with non-zero numbers in the color blue and all fields with the number equal to red zero. Did you understand? rs

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

  • 1

    Thanks for the tip. It worked perfectly, thanks! :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.