Android 实现多个输入框的对话框

jopen 12年前

Android 实现多个输入框的对话框

需要一个布局

    <?xml version="1.0" encoding="utf-8"?>        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:orientation="vertical" >                    <TextView                android:id="@+id/textView1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="姓名" />                    <EditText                android:id="@+id/editTextName"                android:layout_width="match_parent"                android:layout_height="wrap_content" >                        <requestFocus />            </EditText>                    <TextView                android:id="@+id/textView2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="电话号码" />                    <EditText                android:id="@+id/editTextNum"                android:layout_width="match_parent"                android:layout_height="wrap_content" />                </LinearLayout>  
一段代码
    protected void showAddDialog() {                        LayoutInflater factory = LayoutInflater.from(this);                final View textEntryView = factory.inflate(R.layout.dialog, null);                final EditText editTextName = (EditText) textEntryView.findViewById(R.id.editTextName);                final EditText editTextNumEditText = (EditText)textEntryView.findViewById(R.id.editTextNum);                AlertDialog.Builder ad1 = new AlertDialog.Builder(FriendActivity.this);                ad1.setTitle("增加联系人:");                ad1.setIcon(android.R.drawable.ic_dialog_info);                ad1.setView(textEntryView);                ad1.setPositiveButton("是", new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int i) {                                                Log.i("111111", editTextName.getText().toString());                        PersonService personService = new PersonService(                                FriendActivity.this.getBaseContext());                        Person person = new Person();                        person.setName(editTextName.getText().toString());                        person.setPhoneNumber(editTextNumEditText.getText().toString());                        personService.save(person);                            }                });                ad1.setNegativeButton("否", new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int i) {                            }                });                ad1.show();// 显示对话框                    }