package my.testAlertDialog;import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;public class TestAlertDialog extends Activity {
/** Called when the activity is first created. */
private Button btn = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Builder builder = new AlertDialog.Builder(this);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
builder.setIcon(R.drawable.icon);
builder.setMessage("i'm message");
builder.setTitle("i'm title");
builder.setPositiveButton("button1", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText et = (EditText)findViewById(R.id.et);
et.setText("edittext1");
}
});
builder.setNegativeButton("button2", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText et = (EditText)findViewById(R.id.et);
et.setText("edittext1");
}
});
builder.create().show();
}
} );
}
}错误提示:Multiple ers at this line
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder
is not applicable for the arguments (String, new View.OnClickListener(){})
- The type new View.OnClickListener(){} must implement the inherited abstract method
The method onClick(DialogInterface, int) of type new View.OnClickListener(){} must override or implement a supertype method
请问错在哪里了
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;public class TestAlertDialog extends Activity {
/** Called when the activity is first created. */
private Button btn = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Builder builder = new AlertDialog.Builder(this);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
builder.setIcon(R.drawable.icon);
builder.setMessage("i'm message");
builder.setTitle("i'm title");
builder.setPositiveButton("button1", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText et = (EditText)findViewById(R.id.et);
et.setText("edittext1");
}
});
builder.setNegativeButton("button2", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText et = (EditText)findViewById(R.id.et);
et.setText("edittext1");
}
});
builder.create().show();
}
} );
}
}错误提示:Multiple ers at this line
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder
is not applicable for the arguments (String, new View.OnClickListener(){})
- The type new View.OnClickListener(){} must implement the inherited abstract method
The method onClick(DialogInterface, int) of type new View.OnClickListener(){} must override or implement a supertype method
请问错在哪里了
改成
import android.content.DialogInterface.OnClickListener;就可以了
@Override
protected Dialog onCreateDialog(int id) {
return new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.alert)
.setMessage(R.string.dialog_exit_info)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MainActivity.this.finish();
}
})
.setNeutralButton(android.R.string.no, null)
.create();
}