2016-05-12 5 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]属性を追加することを忘れないでくださいする必要があります。

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

属性は、ビルド時にあなたのためのAndroidManifest.xmlにエントリを追加します。これを確認するには、結果のマニフェストが表示されるobj/Debug/androidフォルダを調べます。あなたが名前を使用すると、アクティビティ属性にNameプロパティを追加することができ接頭辞MD5サムを持ってしたくない場合は

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

::次のようなエントリが表示されるはずです

[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

ボタンが機能しない場合、ボタンxmlにonclickプロパティを追加してください –

+0

ありがとうございます!私はちょうど '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を宣言することができます。

関連する問題