我是 Xamarin 的新手,但我正在通过创建 parking 应用程序进行培训。现在我在尝试访问另一个布局时遇到了问题。
这是我的 MainActivity.cs
[Activity(Label = "CustomActionBarParking", MainLauncher = true, Icon = "@drawable/icon", Theme ="@style/CustomActionBarTheme")]
public class MainActivity : Activity
{
private LinearLayout mBarZone;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
ActionBar.SetDisplayShowCustomEnabled(true);
SetContentView(Resource.Layout.action_bar);
mBarZone = FindViewById<LinearLayout>(Resource.Id.linearLayout2);
mBarZone.Click += (object sender, EventArgs args) =>
{
SetContentView(Resource.Layout.zones_list);
};
}}}
在这里,我通过单击“区域”操作栏从我的菜单访问。并打开“区域列表”布局。
从这里我想通过单击蓝色区域操作栏按钮访问另一个布局:vehicle_not_parked。但是我不知道我必须在哪里初始化它,因为当我在 MainAcitivy 类中的 OnCreate 方法中初始化它时,我得到了错误,我的对象可以为空。然后我创建如下所示的 ZonesActivity.cs:
[Activity(Label = "CustomActionBarParking")]
public class ZonesActivity : Activity
{
private LinearLayout mBlueZone;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.zones_list);
mBlueZone = FindViewById<LinearLayout>(Resource.Id.linearLayout2);
mBlueZone.Click += (object sender, EventArgs args) =>
{
SetContentView(Resource.Layout.vehicle_not_parked);
};
}}}
但是当我试图在 Main Activity 类中调用此类时,我必须处理 Bundle savedInstanceState 属性。我真的不知道如何从一个 View -> 第二 View 然后 -> 第三 View 。
最佳答案
如果我没理解错的话,你是在按钮点击事件中交换了布局?我认为最好开始一项新 Activity
mBarZone.Click += delegate {
StartActivity(typeof(ZonesActivity));
};
关于c# - Xamarin 如何通过单击新资源布局来打开另一个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36981771/