0

i have two page(main activity page and favorites page),i working on the favorites page , i want when the user clicked on my favorite button ,that page will be showed on another activity that called favorites page. so i can catch page that user clicked and can transfer that value to another activity(means favorites page) with SharedPreferences, but in favorites page i can set visibility my gone textview. below code worked for me but only one textview only visible for me , for example when btn1 in main activity textview1 in favorites page is visible but when i click on btn2 in main activity the textview2 in favorites is visible but textview1 is no showed and only one textview showed to me, anybody can help me? i want all textview that user clicked be visible Together.

my cod is :

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE); 
    int score = pref.getInt("score", 0);

    List<Boolean> listtt=new ArrayList<Boolean>(Arrays.asList(new Boolean[5]));
    Collections.fill(listtt, new Boolean(false));


    switch (score) {

    case 99:
        if(score == 99){
            pos=99;
            tv_favoritetittle.setText("Nothing");

        }
        break;

    case 100:
        if(score == 100){
            listtt.set(0, true);
            pos=100;
        }
        break;
case 101:
    if(score == 101){
        listtt.set(1, true);
        pos=101;
    }
        break;
case 102:
    if(score == 102){
        listtt.set(2, true);
        pos=102;
    }
    break;

    default:
        break;
    }

and my called function to set visibility of textview:

public void setvisibility(int id){

if(id==100){
    tv_fav7.setVisibility(View.VISIBLE);
}else {tv_fav7.setVisibility(View.GONE);}

if(id==101){
    tv_fav6.setVisibility(View.VISIBLE);
}else {tv_fav6.setVisibility(View.GONE);}       
farzad226
  • 41
  • 7

2 Answers2

0

First you have to call the setvisibility method somewhere.

Second, and more important, you have to notice, that the values that you set into your listtt are never saved anywhere. They won't exist anymore after going to another activity, if you don't save them (manually)!

You can do that e.g. by saving it to the sharedPreferences:

In your onDestroy method iterate through your listtt and put all the values to the sharedPreferences via a SharedPreferences.Editor.

Andi
  • 73
  • 9
0

Just use

'textView.setVisibilty(View.VISIBLE)'

for all the textViews back to back it will appear that they come on at the same time to the user. Do the same for gone.

Taylor Courtney
  • 813
  • 1
  • 6
  • 23