In my app when user clicks a button, it pops up a dialog box. Then upon clicking submit button in the dialog box it opens another dialog box. The problem i'm facing in this scenario is that upon clicking the button of first dialog box it is showing second dialog box but it is not closing the first one And the second problem is that the second dialog box is having an Edittext box and upon using edittext.getText() it is not getting input string.
showCustomDialog() is method to open first dialog box
protected void showCustomDialog() {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(CallBlockerBlacklistViewActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.blockoptionsdialog);
Button button = (Button)dialog.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
selectContactFromDevice();
dialog.dismiss();
}
});
Button button1 = (Button) dialog.findViewById(R.id.manual);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showManualDialog();
}
});
dialog.show();
}
protected void showManualDialog() {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(CallBlockerBlacklistViewActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.manualentry);
final EditText manual_edittext=(EditText) dialog.findViewById(R.id.manualedittext);
Log.d("txtB" , String.valueOf(manual_edittext));
manual_number=manual_edittext.getText().toString();
Button button1 = (Button) dialog.findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
addtolist(manual_number);
dialog.dismiss();
}
});
dialog.show();
}
addtolist is not passing the required number.
Answer #1 is pretty easy: You only have dialog.dismiss() in your first on click, but not your second.
Button button = (Button)dialog.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
selectContactFromDevice();
dialog.dismiss();
}
});
Button button1 = (Button) dialog.findViewById(R.id.manual);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showManualDialog();
}
});
Answer #2 is that you are calling getText in your viewCreation. You need to wait for the user to input text, and hit the button. Move the getText() inside your onClick() like so:
Button button1 = (Button) dialog.findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//This line needs to go inside.
String manual_number=manual_edittext.getText().toString();
addtolist(manual_number);
dialog.dismiss();
}