i'm new to create dynamic dialog, and this is my issue:
When i show the dialog with builder.create().show(), everything works fine, but when I try to show after assign it to AlertDialog it doesn't show.
this is my code:
final EnablerButton enablerPositiveButton=new EnablerButton(TextToMonitor);
final AlertDialog.Builder builder = new AlertDialog.Builder(MyAct.this)
.setView(ll)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
enablerPositiveButton.interrupt();
ProgressDialog progressBar;
progressBar = new ProgressDialog(parentActivity);
progressBar.setCancelable(false);
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(1);
progressBar.setMax(10000);
progressBar.show();
}
}).setCancelable(false);
AlertDialog alert = builder.create();
alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
enablerPositiveButton.setButtonToEnable(alert.getButton(AlertDialog.BUTTON_POSITIVE));
enablerPositiveButton.start();
alert.show();
And this is my thread that check if the fields are empty:
public class EnablerButton extends Thread {
public boolean run=true;
Button btnToEnable;
LinkedList <EditText> editTextsToCheck;
public EnablerButton(LinkedList<EditText> editTexts){
this.editTextsToCheck = editTexts;
}
@Override
public void run(){
while (run) {
boolean alright = true;
for (EditText editText : editTextsToCheck) {
if (editText.getText().toString().isEmpty()) alright = false;
}
if (alright) btnToEnable.setEnabled(true);
else btnToEnable.setEnabled(false);
try {
sleep(500);
}catch(InterruptedException e){
e.printStackTrace();
run=false;
}
}
}
public void setButtonToEnable(Button toEnable){
this.btnToEnable = toEnable;
}
public void interrupt(){
run=false;
}
}
Aucun commentaire:
Enregistrer un commentaire