2012-03-06 111 views
0

进出口试图连接起来,阵列[1]发动活性,但其示出了我一个错误在这条线
意图I1 =新意图(此,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

嗨,你有你的解决方案吗? – 2012-03-06 19:20:17

回答

2

变化

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

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

,并与该走的是内部发生的活动的名称取代 “TheNameOfYourActivity”。

+0

你先生是天才谢谢你 – Hashey100 2012-03-06 20:03:28

1

既然你已经开始在意向对话框的onclick监听器,将引用对话框实例,而不是您的活动类(我假设你正在呼吁从代码)。

要解决此问题,您需要创建一个变量来存储对您的活动的引用,并使用该变量代替这个