GAMA
GAMA

Reputation: 5996

List value gets altered on orientation change

Referring to below screenshot, ListView consists of 3 TextView.

Depending on the value of 3rd TextView, Respective color is assigned to the text of 3rd TextView.

i.e. 1.) Green if value>0

2.)Red if value<0

3.) White if value=0 (default)

Following code snippet is used inside an Adapter.

if (Float.parseFloat(map.get(RecentChg_COLUMN)) > 0) {
            holder.tvRecentChg.setTextColor(Color.GREEN);
        }

else if (Float.parseFloat(map.get(RecentChg_COLUMN)) < 0) {
            holder.tvRecentChg.setTextColor(Color.RED);
        }

1st screen shows the correct output.

But on orientation change, output comes as shown in 2nd screen.

Lets concentrate on SHARIABEES, for which value=0.0

Initially it appears in white, but on orientation change it's color changes to Red.

I have no idea why it might be happening.

Any suggestions welcomed....

screen

Upvotes: 0

Views: 124

Answers (1)

Pratik
Pratik

Reputation: 30855

set the else part also for value = 0

if (Float.parseFloat(map.get(RecentChg_COLUMN)) > 0) {
        holder.tvRecentChg.setTextColor(Color.GREEN);
    }

else if (Float.parseFloat(map.get(RecentChg_COLUMN)) < 0) {
        holder.tvRecentChg.setTextColor(Color.RED);
    }
else if (Float.parseFloat(map.get(RecentChg_COLUMN)) == 0) {
        holder.tvRecentChg.setTextColor(Color.WHITE);
    }

and in the androidmanifest.xml file in you tag set this

<activity android:name=".HomeActivity" android:label="@string/app_name" android:configChanges="orientation">

Upvotes: 4

Related Questions