1
I have in my small project a alertDialog, that is called to give some options to the user. Everything was working, until suddenly the buttons (positiveButton, negativeButton and neutralButton) disabled in all my AlertDialog of the project. The alertDialog still running, but the buttons are in a weaker color (typical of when disabled) and do not call the methods that are within their respective onClick();.
Follows my code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.generate_pdf_2:
//Aqui está meu código original, que estava funcionando alguns dias atras.
/*new AlertDialog.Builder(getActivity()).setTitle("Criando Recibo")
.setMessage("Tem certeza que deseja criar o recibo?")
.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((AlertDialog)dialog).getButton(which).setVisibility(View.VISIBLE);
GeradorRecibo geradorRecibo = new GeradorRecibo(getActivity(), cliente);
Toast.makeText(getActivity(), "Recibo gerado com sucesso!", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("Não", null)
.show();*/
//Aqui está uma tentativa que foi o mais parecido com a possivel solução do erro que encontrei, ou seja, segue esta logica porem, obviamente nao é esta a solução pois continua sem funcionar exatamente do mesmo jeito.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Criando Recibo");
builder.setMessage("Deseja criar o recibo?");
builder.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
GeradorRecibo geradorRecibo = new GeradorRecibo(getActivity(), cliente);
Toast.makeText(getActivity(), "Recibo gerado com sucesso!", Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
final Button btn = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
btn.setEnabled(true);
dialog.show();
return true;
But this code is identical to the OP. This does not seem to be an attempt to solve the problem.
– user28595
It is not identical, dialog.getButton() should be after the dialog call.show(), tested in api 23.
– Diniz
So guys, I appreciate the comments. I ended up discovering what it was. They were just problems with the permissions, which now changed on android. Above api 23 the app should present to the user a request for permissions while running the application, as the functions of my alertDialog require access to internal storage, have been disabled.
– Cesar Roberto Martins