I have designed an alertdialog of which when the user press the save button, it is hoped that it can return the user’s entered editTexts (the players’ scores) in the alert dialog back to the activity for further processing.
How could this be made? Would there be any samples? Many thanks!!
I have performed the below but the output now is it cannot recognize what is being input and ask user to input non-blank editText (goes through the else route at bottom):
public OnClickListener NewRowButtonListener = new OnClickListener()
{
@Override
public void onClick(View v)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("Add Scores"); //set title
View view = getLayoutInflater().inflate(R.layout.custom_dialog_add, null);
dialog.setView(view);
dialog.create();
final AlertDialog test = dialog.create();
SlotAlert_add_EditText = (EditText) view.findViewById(R.id.Slot_Alert_add_EditText);
P1Alert_add_ScoreEditText = (EditText) view.findViewById(R.id.P1_Alert_add_ScoreEditText);
P2Alert_add_ScoreEditText = (EditText) view.findViewById(R.id.P2_Alert_add_ScoreEditText);
P3Alert_add_ScoreEditText = (EditText) view.findViewById(R.id.P3_Alert_add_ScoreEditText);
P4Alert_add_ScoreEditText = (EditText) view.findViewById(R.id.P4_Alert_add_ScoreEditText);
Button alert_add_save = (Button) view.findViewById(R.id.Alert_add_SaveButton); //find the Button object within the inflated view
alert_add_save.setOnClickListener(addButtonListener); //set the onClickListener
test.show(); //show the dialog
}
};
and then
public OnClickListener addButtonListener = new OnClickListener()
// create a new Button and add it to the ScrollView
{
private String SlotAppend0EditText;
@Override
public void onClick(View v)
{
SlotEditText.setText(""+SlotAlert_add_EditText); //try to set EditText in MainActivity using the one in the alert dialog above
P1ScoreEditText.setText(""+P1Alert_add_ScoreEditText);
P2ScoreEditText.setText(""+P2Alert_add_ScoreEditText);
P3ScoreEditText.setText(""+P3Alert_add_ScoreEditText);
P4ScoreEditText.setText(""+P4Alert_add_ScoreEditText);
if (SlotEditText.getText().length() <4 &&
SlotEditText.getText().length() > 0 &&
P1ScoreEditText.getText().length() > 0 &&
P2ScoreEditText.getText().length() > 0 &&
P3ScoreEditText.getText().length() > 0 &&
P4ScoreEditText.getText().length() > 0 )
{
SaveScoresToFile(SlotAppend0EditText,
P1ScoreEditText.getText().toString(),
P2ScoreEditText.getText().toString(),
P3ScoreEditText.getText().toString(),
P4ScoreEditText.getText().toString());
} // end if
else (another alert message saying please enter valid input) //NOW THE RESULT IS SHOWING THIS!
see this
Alert Dialog