tags:

views:

26

answers:

1

How i can return String value from onClick method?

public class DialogWithInputBox extends Activity {
                /** Called when the activity is first created. */
                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.main);

                    final AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    final EditText input = new EditText(this);
                    alert.setView(input);
                    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            String value = input.getText().toString().trim();

                        }
                    });

                    alert.setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            });
                    alert.show();

                }
            }
A: 

Again I answer to my question), onClick - doesn't want to change not final data, i created final List<String> (he let you to change him) and in onClick use list.add(value)

Sergey