Сохранение EditText из диалогового окна в Android - PullRequest
0 голосов
/ 16 июля 2011

Кто-нибудь знает, как сохранить текст, который пользователь введет после всплывающего диалогового окна? Сначала я надуваю представление для диалогового окна, затем позволяю пользователю вводить строку и как-то ее отображать. Вот мой код для раздувания диалогового окна. У меня вопрос: как сохранить текст, который кто-то вводит в мое поле, из окна AlertDialog. Мой XML внизу

@Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_TEXT_ENTRY:

            LayoutInflater mInflater = LayoutInflater.from(this);
            final View textEntryView = mInflater.inflate(
                    R.layout.alert_text_entry, null);
            return new AlertDialog.Builder(AlarmList.this)
                    .setIcon(R.drawable.alert_icon)
                    .setTitle("Enter your name")
                    .setView(textEntryView)
                    .setPositiveButton("accept",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {



                                }
                            })
                    .setNegativeButton("Cancel", new OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).create();
        }
        return null;
        }


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView android:id="@+id/rowTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="70dp"
    android:padding="12dp"
    android:textSize="16sp" >
  </TextView>

  <EditText android:id="@+id/alarm_name_text"
  android:layout_height="3dp" 
  android:text=""
  android:layout_below="@+id/rowTextView" 
  android:layout_width="wrap_content" 
  android:layout_alignLeft="@+id/rowTextView"
  android:layout_alignRight="@+id/rowTextView">
  </EditText>

  <CheckBox android:id="@+id/CheckBox01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dp"
    android:layout_alignParentRight="true" android:layout_marginRight="6sp"
    android:focusable="false">
  </CheckBox>

</RelativeLayout>

1 Ответ

1 голос
/ 16 июля 2011

Как упоминалось в документах EditText, вы можете вызвать getText () , чтобы получить текст из представления EditText.

...