【发布时间】:2016-02-04 19:47:45
【问题描述】:
我正在开发一个 Android 应用程序。
我有一些存储在 SharedPreferences 中的属性。
我需要布局 - 直到共享首选项中存储的值没有文本。
当值被存储时,我需要让布局可见。
zakazat.Click += delegate {
var intent = new Intent (this, typeof(CartActivity));
intent.PutExtra ("title", (string)(firstitem ["post_title"]));
intent.PutExtra ("price", (string)(firstitem ["price"] + " грн"));
intent.PutExtra ("weight", (string)(firstitem ["weight"] + "г"));
StartActivity (intent);
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (this);
ISharedPreferencesEditor editor = prefs.Edit ();
editor.PutString ("title", (string)(firstitem ["post_title"]));
editor.PutString ("price", (string)(firstitem ["price"] + " грн"));
editor.PutString ("weight", (string)(firstitem ["weight"] + "г"));
editor.Apply ();
};
在其他活动中:
private void Display (){
LinearLayout display2 = FindViewById<LinearLayout> (Resource.Id.linearLayout12);
//LinearLayout display = FindViewById<LinearLayout> (Resource.Id.linearLayout13);
TextView productname = FindViewById<TextView> (Resource.Id.posttittle);
TextView price = FindViewById<TextView> (Resource.Id.price);
TextView weight = FindViewById<TextView> (Resource.Id.weight);
productname.Text = Intent.GetStringExtra ("title");
price.Text = Intent.GetStringExtra("price");
weight.Text = Intent.GetStringExtra("weight");
display2.Visibility = ViewStates.Visible;
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (this);
string product = prefs.GetString ("title", "");
string _price = prefs.GetString ("price", "");
string _weight = prefs.GetString ("weight", "");
productname.Text = product;
price.Text = _price;
weight.Text = _weight;
//price.Text = Intent.GetStringExtra("price");
//weight.Text = Intent.GetStringExtra("weight");
//display2.Visibility = ViewStates.Visible;
productname.Visibility = ViewStates.Visible;
price.Visibility = ViewStates.Visible;
weight.Visibility = ViewStates.Visible;
}
我该怎么做?
【问题讨论】:
-
我不确定你在问什么。您是否希望某些
TextViews 将其visibility设置为gone,直到您可以从SharedPreferences...检索文本? -
是的,我想要它@PPartisan