2012-03-21 77 views
0

我有一些代码来创建一个基本的对话框有几个选项 - 如果我选择某个选项,我收到一条消息说这已被点击 - 我知道非常基本的东西。Android - 基本语法需要帮助

这是我的代码:

公共方法 - 公共无效的onClick(DialogInterface对话,诠释它,布尔器isChecked)返回一个错误,指出它必须重写超类方法。

有谁能告诉我这种超类方法是什么吗?我似乎无法在任何地方找到它。 在此先感谢。

Chilun

package net.learn2develop.Dialog2; 

import android.app.Activity; 
import android.os.Bundle; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

public class MainActivity extends Activity { 
    CharSequence[] items = { "Google", "Apple", "Microsoft" }; 
    boolean[] itemsChecked = new boolean [items.length]; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button btn = (Button) findViewById(R.id.btn_dialog); 
     btn.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       showDialog(0); 
      } 
     }); 
    } 

    @Override 
    protected Dialog onCreateDialog(int id) { 
     switch (id) { 
     case 0: 
      return new AlertDialog.Builder(this) 
      .setIcon(R.drawable.ic_launcher) 
      .setTitle("This is a dialog with some simple text...") 
      .setPositiveButton("OK", new 
       DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 
         // TODO Auto-generated method stub 
         Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); 
        } 
      }) 
      .setNegativeButton("Cancel", new 
       DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 
         // TODO Auto-generated method stub 
         Toast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show(); 
        } 
    }) 
    .setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() { 
         @Override 
         **public void onClick(DialogInterface dialog, int which, boolean isChecked)** { 
         // TODO Auto-generated method stub 
         Toast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!" : " unchecked!"), Toast.LENGTH_SHORT).show(); 
         } 
        } 
     ) 
     .create(); 
     } 
     return null; 
    } 
} 
+0

http://stackoverflow.com/questions/9775946/override-problems-with-viewpagerindicator/9775978#9775978 – 2012-03-21 15:16:35

回答

1

代码看起来OK。检查您的项目属性并查看您的项目符合性是否为1.6。右键单击您的项目 - >Properties - >根据Java Compiler - >Compiler compliance should be set to 1.6。 Java 1.5不允许在那里使用@Override注释。