How to display a listview with only one line with the color changed?

Asked

Viewed 88 times

1

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

lv.setBackgroundColor(Color.CYAN);  

Thank you in advance!

1 answer

2


Hello, Daniel. A suggestion is to make a layout with the items in your Listview and associate it with a Listpter. Take a look at the 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;
  }
};

Browser other questions tagged

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