Change color and font style of Listview not working

0
Hello, I am still a baby in programming, I can not deny that I have advanced and you have helped, well I have a listview with search, that the list comes from a string array, the code itself works perfect, but I I'm trying to change the color of the text and the font to bold, from the list, and as well I can do this with the code below, but in my onclick I have an "if" for each text clicked, some 8 texts, and there it is problem the onclick does not work when I change the color and font of the text, when there are not these changes everything works fine. Since then thank you all. The above question where it says possibly is duplicate has a completely different code! Here is 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);
    
asked by anonymous 21.02.2016 / 12:14

1 answer

0

In the link that Jr. Moreira sent, contains the answer to your question. If you look below in the answer, it gives the example using anonymous class.

Here is the snippet of the 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 question: How to change the Text Color of a listView?

    
25.02.2016 / 20:32