How to present a listView with only one line with the changed color?

1

It may seem easy, but I'm catching it. I needed a list of 10 names, for example the 3rd name in green. As I do to get his position, I'm not getting it, I need to present this list with the modified color as soon as I open the screen. can someone give a help? to change the color of all the components in the list I just hedge the background color of my listView.

lv.setBackgroundColor(Color.CYAN);  

Thank you in advance!

    
asked by anonymous 21.09.2015 / 16:48

1 answer

2

Hello, Daniel. One suggestion is to make a layout with the items in your ListView and associate it with a ListAdapter. Take a look at Adapter

Example:

         ArrayAdapter<String> meuAdapter = new ArrayAdapter<String>getApplicationContext(), 
                            android.R.layout.minha_lista_001, 
                            minhaLista) {

            @Override
            public View getView(int posicao, View convertView, ViewGroup parent) {

                View view = super.getView(posicao, convertView, parent);
                TextView texto = (TextView) view.findViewById(android.R.id.texto1);

                if (posicao == 3 ) {
                    text.setTextColor(Color.RED);
                }else{

                //alguma coisa

    }  return view;
  }
};
    
21.09.2015 / 17:10