I have a alertdialog that I know I will be using in multi classes thoughout my app and you can tell I would rather place it in its own class and call it when nessary. Its a simple text field and ok/cancel buttons. I always want to pass some text into it and after the user has clicked OK I want a variable to be updated with the updated text string
Whats the best way at converting this code so it can be used else where
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.dialog_layout, null);
editTextfield = (EditText) layout.findViewById(R.id.comment_text);
editTextfield.setText(text);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle(R.string.title);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
text = editTextfield.getText().toString();
removeDialog(DIALOG);
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
removeDialog(DIALOG);
}
});
AlertDialog dialog = builder.create();
return dialog;
Thanks for you time
You should check out this tutorial it shows you exactly how to do what you are trying to do. You have to extend the Dialog class.
Custom Dailog class