Chapter 2 Dialog Super Class Override
I am working on the Dialog example and I am getting an error I can't find anywhere else in the forums. On the OnClick that looks at the check boxes is giving me these errors:
- The method onClick(DialogInterface, int, boolean) of type new DialogInterface.OnMultiChoiceClickListener(){} must override a superclass
method.
- implements android.content.DialogInterface.OnMultiChoiceClick Listener.onClick
Any help or suggestions would be appreciated. My code is below.
package com.example.dialog;
import android.os.Bundle;
import android.app.Activity;
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 DialogProject extends Activity {
CharSequence[] items = {"Google","Apple", "Microsoft" };
boolean[] itemsChecked = new boolean [items.length];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
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)
{
Toast.makeText(getBaseContext(), "Ok Clicked!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int whichButton)
{
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){
Toast.makeText(getBaseContext(),items[which] + (isChecked ? " checked": " unchecked"),
Toast.LENGTH_SHORT).show();
}
}
)
.create();
}
return null;
}
}
|