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;
}
}
http://stackoverflow.com/questions/9775946/override-problems-with-viewpagerindicator/9775978#9775978 – 2012-03-21 15:16:35