尝试使用AlertDialog作为输入进行简单的更改视图活动。 但出现错误'eglSurfaceAttrib(1146):错误0x3009(EGL_BAD_MATCH)':
这是我的AlertDialog活动:
package caraoucoroa.studio.brunocasamassa.signos;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
/**
* Created by bruno on 02/02/2017.
*/
public class MainActivity extends AppCompatActivity {
private Button botao;
private AlertDialog.Builder alert;
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_hello);
botao = (Button) findViewById(R.id.button);
botao.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//creating alert
alert = new AlertDialog.Builder(MainActivity.this);
//alert title
alert.setTitle("Entrando");
//set message
alert.setMessage("Deseja entrar?");
alert.setCancelable(false);
alert.setIcon(android.R.drawable.ic_delete);
//Negative Button
alert.setNegativeButton("Não", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"Comeback Anytime", Toast.LENGTH_SHORT).show();
}
});
//Positive Button
alert.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//startActivity(new Intent(MainActivity.this, SignosActivity.class));
Toast.makeText(MainActivity.this,"Comeback Anytime", Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
答案 0 :(得分:1)
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setMessage("Are you sure you want to exit?");
builder1.setCancelable(true);
builder1.setPositiveButton(
"Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.this.finish();
}
});
builder1.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();