0

I have Two activity

In one I receive attributes and save them to SharedPreferences

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (this);
            ISharedPreferencesEditor editor = prefs.Edit ();
            Console.WriteLine(Code1);
            editor.PutString ("title", (string)(firstitem ["post_title"]));
            editor.PutString ("price", (string)(firstitem ["price"] + " грн"));
            editor.PutString ("count", counttext.Text);

            editor.Apply ();

On second I show what in SharedPreferences.

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (this);
        string product = prefs.GetString ("title","");
        string _weight =  prefs.GetString ("count","");
        string _price = prefs.GetString ("price","");
        Code2 = Intent.GetStringExtra ("Code1");
        _count = _weight;


        productname.Text = product;
        weight.Text = _weight;
        price.Text = _price;

I need to keep LinearLayout visibility:GONE when attribute doesn't write to shared preference in first activity.

How I can do this?

And second question. Can I save to SharedPreferences attributes and show them on same activity?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0
  1. In your first activity you can check

        if (string.IsNullOrEmpty (product) || string.IsNullOrEmpty (_weight) || string.IsNullOrEmpty (_price)) {
                    myLinearLayout.Visibility = ViewStates.Gone;
                }
    
  2. Of course you can, read the question here

Community
  • 1
  • 1