2016-05-12 44 views
-1

我的意思是用“设置”按钮创建一个应用程序,这会在按下时创建一个新的活动。我想要这个新的活动来显示实际的设置页面。无法看到新的活动

这里的设置按钮的XML代码:

<Button 
android:text="Settings" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/buttonResSettings" /> 

这里就是我所说的新的活动代码,这是我的主要活动的OnCreate

Button resSetButton = FindViewById<Button>(Resource.Id.buttonResSettings); 
resSetButton.Click += delegate { 
var ResSetAct = new Intent(this, typeof(ResSettingsActivity)); 
ResSetAct.PutExtra("res", res); 
StartActivity(ResSetAct); 
}; 

这里的代码我新活动:

public class ResSettingsActivity : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set the view to ResSettings(.axml) 
     SetContentView(Resource.Layout.ResSettings); 

     //Fetch the data of the variables 
     string res = Intent.GetStringExtra("res"); 

     //Map the elements of the view to usable objects 
     EditText CurRes = FindViewById<EditText>(Resource.Id.editCurRes); 

     //Display the current values of the settings 
     CurRes.Text = res; 
    } 
} 

建设和使用其余的ap p在模拟器中没有问题,但是当我点击该设置按钮时,什么也没有发生(除了默认的onClick按钮设计更改)。

回答

2

你需要记住的[Activity]属性添加到您的新活动类:

[Activity(Label = "Res Settings")] 
public class ResSettingsActivity : Activity 
{ 
    ... 
} 

的属性将在生成时添加在AndroidManifest.xml中的条目为您服务。您可以通过查看obj/Debug/android文件夹来查看结果清单。您将看到一个条目:

<activity android:label="Res Settings" android:name="md51237869127761dfsa77sadvfb.ResSettingsActivity" /> 

如果不希望名字有一个MD5和前缀可以在Name属性添加到活动属性的更多信息:

[Activity(Label = "Res Settings", Name = "my.package.name.ResSettingsActivity")] 
+0

感谢您的领导!但问题依然存在。 – Slath

+0

我无法重现您的问题,在此处可以正常工作。 – Cheesebaron

+0

我通过Parveen Prajapati的建议将'var ResSetAct'改成'Intent ResSetAct'来解决它。 – Slath

1
Intent theintent = new Intent(A.this,B.java); 
theintent.putExtra("name",john); 
startActivity(theintent); 

同时声明清单文件中的类b.java

+0

if button will not work then onclick property in button xml –

+0

Thanks!谢谢!我刚将'var ResSetAct'改成'Intent ResSetAct',增加了Cheesebaron提到的内容。现在它就像一个魅力! – Slath

+0

好吧,那太好了。 –

0
Intent i = new Intent(getApplicationContext(), ActivityTwo.class); 

// Set the request code to any code you like, you can identify the 
// callback via this code 
startActivity(i); 
0
Intent intent = new Intent(this, DisplayMessageActivity.class); 
    intent.putExtra(EXTRA_MESSAGE, message); 
    startActivity(intent); 

您可以像这样传递意图,并在清单文件中声明类DisplayMessageActivity