Changing Listview font color and style does not work

Asked

Viewed 379 times

0

Hello, I am still a baby in programming, I can not deny that I have advanced and vcs have helped, see well I have a listview with search, that the list comes from a string array, the code itself works perfect, but I’m trying to change the color of the text and the font to bold, from the list, and so I can do it with the code below, but in my onclick I have an "if" for each text clicked, some 8 texts, and so the problem onclick does not work when I change the color and font of the text, when there are these changes works normal. From now on, thank you all. The partegunta above where it says it is possibly duplicated has a completely diffident code! Follow part of my code:

lvbr = (ListView) findViewById(R.id.lvsbr);
etbr = (EditText) findViewById(R.id.etsr);

lst = getResources().getStringArray(R.array.sonsbr);


lvbr.setAdapter(new ArrayAdapter<String>(this, R.layout.seila, R.id.txtcor, lst));
    CarregarEncontrados();

lvbr.setAdapter(new ArrayAdapter<String>(cardiobrasil.this, R.layout.seila, R.id.txtcor, lst_Encontrados));

        }
    });


lvbr.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {



            if (((TextView) view).getText().equals("Salto")) {
                setContentView(R.layout.brc01);
  • 2
  • Thank you, the above subject is really similar, but I don’t use a pro Dapter class I did right there in the very own Activity class, beauty I can change the text color of the list items and the font type, but as I said I have an if in onclick for each text clicked, Then when the list is with the color and the font changed it doesn’t go where it should, or better simply doesn’t work. drew?

1 answer

0

On the link Junior Moreira sent, it contains the answer to his question. If you look further down on the answer, it gives the example using anonymous class.

Follow the section of modified code for your need:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.seila, lst_Encontrados) {

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

        View view = super.getView(position, convertView, parent);

        // teste aqui se o view é referente ao seu textview do layout
        if (view == parent.findViewById(R.id.seutextview) {
            ((TextView) view).setTextColor(cor); // substitua 'cor' pela cor desejada
            ((TextView) view).setTypeface(null, Typeface.BOLD);
        }

        return view;
    }

};

lvbr.setAdapter(adapter);

Similar issue: Changing the Text Color of a listview?

Browser other questions tagged

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