2012-03-06 8 views
0

配列[1]をリンクしてアクティビティを開始しようとしましたが、この行にエラーが表示されています
インテントi1 =新しいインテント(this、Difficulty.class);いずれかが見ている場合はイムは間違っているあなたが意図を始めているので

エラーは「(新DialogInterface.OnClickListener(){}クラス)コンストラクタ意図を未定義である」読み込みボタンをリンクしてアクティビティを起動する

 final CharSequence[] items = {"Red", "Green", "Blue"}; 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Pick a color"); 
     builder.setItems(items, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int item) { 

      if ("Green".equals(items[1])) 
      {Intent intent = new Intent(); 
      Intent i1 = new Intent(this, Diff.class); 
      startActivity(i1);;} 

     } 
     }).show(); 
     AlertDialog alert = builder.create(); 
+0

こんにちは、あなたの解決策を得ましたか? –

答えて

2

変更

Intent i1 = new Intent(this, Diff.class); 

と、これは内部に行われている活動の名前で "TheNameOfYourActivity" を交換してください。

+0

あなたは天才です、ありがとう – Hashey100

1

私を助けてくださいこのは、アクティビティクラス(コードを呼び出すと仮定している)ではなくダイアログインスタンスを参照します。

この問題を解決するには、アクティビティへの参照を保持する変数を作成し、それをの代わりにの代わりに使用する必要があります。

Intent i1 = new Intent(TheNameOfYourActivity.this, diff.class); 

関連する問題