I came a cross this problem: I can't get EditText (int) value, turn it in to a string and then use it in Alert Dialog.
(I am making a Phone number Verification. Not an advanced one! Just simple that confirms the new user real.) Here is my code:
sms_verification:
public class sms_verification extends AppCompatActivity {
ImageButton send;
EditText text;
String myEditValue;
public static int phone;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_verification);
send = (ImageButton)findViewById(R.id.imageButton);
text = (EditText)findViewById(R.id.editText);
}
public void AlertDialog(View view) {
myEditValue = text.getText().toString();
phone = Integer.parseInt(myEditValue);
AlertDialog.Builder alertdlg = new AlertDialog.Builder(this);
alertdlg.setMessage("Confirmation")
.setCancelable(false)
.setMessage("Is " + phone +" your phone number?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setContentView(R.layout.sms_verification2);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertdlg.create();
alertDialog.show();
}
}