Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使布局不可见_C#_Android_Xamarin - Fatal编程技术网

C# 如何使布局不可见

C# 如何使布局不可见,c#,android,xamarin,C#,Android,Xamarin,我正在开发一个Android应用程序 我有一些存储在SharedReferences中的属性 我需要布局-直到共享首选项中存储的值没有文本为止 存储值时,我需要使布局可见 zakazat.Click += delegate { var intent = new Intent (this, typeof(CartActivity)); intent.PutExtra ("title", (string)(firstitem ["post_title"

我正在开发一个Android应用程序

我有一些存储在SharedReferences中的属性

我需要布局-直到共享首选项中存储的值没有文本为止

存储值时,我需要使布局可见

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;
    }
private void显示(){
LinearLayout display2=FindViewById(Resource.Id.LinearLayout2);
//LinearLayout display=findviewbyd(Resource.Id.linearLayout13);
TextView productname=FindViewById(Resource.Id.PostTitle);
TextView price=findviewbyd(Resource.Id.price);
TextView-weight=findviewbyd(Resource.Id.weight);
productname.Text=Intent.GetStringExtra(“标题”);
price.Text=Intent.GetStringExtra(“价格”);
weight.Text=Intent.GetStringExtra(“重量”);
display2.Visibility=ViewStates.Visible;
iSharedReferences prefs=PreferenceManager.GetDefaultSharedReferences(此);
string product=prefs.GetString(“title”,”);
string _price=prefs.GetString(“price”,”);
string _weight=prefs.GetString(“weight”,”);
productname.Text=产品;
Text=_价格;
文本=_权重;
//price.Text=Intent.GetStringExtra(“价格”);
//weight.Text=Intent.GetStringExtra(“重量”);
//display2.Visibility=ViewStates.Visible;
productname.Visibility=ViewState.Visible;
price.Visibility=ViewStates.Visible;
weight.Visibility=ViewStates.Visible;
}

如何操作?

默认情况下,您的视图可见性设置可见性(已消失) 之后。 首先,每秒钟检查一次SharedReference值是否不等于默认值。如果为真,则视图可见性设置为visibility visible 试试这段代码我不确定,但我认为这段代码会成功

Thread t = new Thread() {

  @Override
  public void run() {
    try {
      while (!isInterrupted()) {
        Thread.sleep(1000);
        runOnUiThread(new Runnable() {
          @Override
          public void run() {
       SharedPreferences shared = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
String value = shared.getString("key","Default");
if(!value.equalsto("Default"){
view.setVisibility(View.VISIBLE);
}
          }
        });
      }
    } catch (InterruptedException e) {
    }
  }
};

t.start();

我不知道你在问什么。你想让一些
TextView
s的
可见性设置为
gone
,直到你可以从
SharedReferences
检索文本为止吗?是的,我想it@PPartisan