I’m having trouble saving String-values that resides within the edittext.
What happens is, the dialog shows, with edittext, an ok and a cancel-button.
When the OK button is pushed, what i want to happen is for the bar-variable to get the string-value from the edittext.
public void dialog(){
final Dialog dialog = new Dialog(myClass.this);
dialog.setContentView(R.layout.mydialog);
dialog.setTitle("I'm soo smart. S-M-R-T. Smart.");
dialog.setCancelable(true);
dialog.show();
Button okButton = (Button) dialog.findViewById(R.id.dialog_OK_BUTTON);
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try{
LayoutInflater factory = LayoutInflater.from(Inloggning.this);
final View textEntryView = factory.inflate(R.layout.myDialog, null);
final EditText barText= (EditText) textEntryView.findViewById(R.id.dialog_FOO);
// this gets returned empty.
bar= barText.getText().toString();
System.out.println("foo: "+bar);
//call();
dialog.hide();
}
catch(Exception e){
// do whatever nessesary.
}
}
});
Button cancelButton = (Button) dialog.findViewById(R.id.dialogbtn_cancel);
cancelButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
}
Can someone shed some light onto this please?
EDIT: This is sample code. Actual code does not have duplicates names on variables.
2ND EDIT: removed duplicates..
Check if
barTextis null.What happens if you declare it out of the
onClicklistener?Maybe change:
to: