N
N
Nikolai Zebrev2015-01-20 12:07:04
Java
Nikolai Zebrev, 2015-01-20 12:07:04

Change text size of item listview android?

Greetings!
There is a problem that needs to be solved.
When creating an application, I take a part of the text from HTML and parse it into JSON, after clearing it of unnecessary garbage. Then I insert json objects as a list in listview. Everything is good and pleasant here.
But, in my application I have an option to increase and decrease the text in the item listview. It doesn't work correctly.
Here is how I resize:

int sizeText = 14;

private boolean setChangeTextSize(){
        int childCount = lv.getChildCount();

        float fSize = Float.parseFloat( sizeText+"");

        int i = 0;

        while (i < childCount){
            View v = lv.getChildAt(i);
            TextView tx = (TextView) v.findViewById(R.id.stings);
            tx.setTextSize(fSize);
            i++;
        }
        return false;
    }

The code is parsed correctly, but if you scroll the list a little down or up, the text size starts to jump (There must be a political joke here).
And here's the question, why is the text jumping?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Strunin Andrey, 2015-01-20
@NickoliaDeGori

Use ArrayAdapter and forget about problems. No other way. At the same time, you can customize the view of the list to suit your needs.
http://habrahabr.ru/post/133575/
Custom markup for listview item with font sizes there is the best option. Implement all dynamic appearance changes in the getView method of your ArrayAdapter.
Nothing will jump!

I
IceJOKER, 2015-01-20
@IceJOKER

In the getView in the adapter, set the size too.
This is because when scrolling, what goes beyond the frame is then recreated using getView and the TextView for which you set the size goes to Narnia) It is
recommended to create a static holder class with static fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question