【问题标题】:Android - need assistance with basic syntaxAndroid - 需要基本语法方面的帮助
【发布时间】:2012-03-21 14:59:58
【问题描述】:

我有一些代码来创建一个带有多个选项的基本对话框 - 如果我选择某个选项,我会收到一条消息,说它已被点击 - 我知道非常基本的东西。

这是我的代码:

公共方法 - public void onClick(DialogInterface dialog, int which, boolean isChecked) 返回一个错误,指出它必须覆盖超类方法。

谁能告诉我这个超类方法是什么?我似乎无法在任何地方找到它。 提前致谢。

赤轮

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;
    }
}

【问题讨论】:

标签: android


【解决方案1】:

代码看起来没问题。检查您的项目属性并查看您的项目合规性是否为 1.6。右键单击您的项目 -> Properties -> 在Java Compiler 下 -> Compiler compliance should be set to 1.6。 Java 1.5 不允许在此处使用 @Override 注释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    相关资源
    最近更新 更多