android从对话框中删除视图?

时间:2012-04-11 05:52:52

标签: java android android-2.2-froyo android-dialog

如何从此对话框中删除视图?我知道我可以从 LinearLayout.removeView(id)(LinearLayout.removeView(View))中删除一个视图,所以如果有人可以告诉我如何获取(LinearLayout)R.layout.database_creation_form,那也会很好。我使用的是Android-SDK V7

Java代码:

@Override
protected DialogInterface onCreateDialog(int id){
    LayoutInflater factory = LayoutInflater.from(getBaseContext());
    final View textEntryView = factory.inflate(R.layout.database_creation_form, null);
    setDialogViewAttributes(textEntryView);
    final EditText editText = (EditText)textEntryView.findViewById(R.id.create_form_db_name_et2);
    final Spinner spinner = (Spinner)textEntryView.findViewById(R.id.create_form_type_sp);
    return new AlertDialog.Builder(FileBase.this)
        .setTitle(R.string.create_database_string)
        .setView(textEntryView)
        .show();
}

database_creation_form的XML:

<?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" android:paddingTop="25px">


<TextView
    android:id="@+id/create_form_db_name_tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/create_form_db_name"
    android:textAppearance="?android:attr/textAppearanceLarge" android:paddingBottom="25px"/>

<EditText
    android:id="@+id/create_form_db_name_et2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:inputType="text">

    <requestFocus />
</EditText>


<TextView
    android:id="@+id/create_form_type_tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/create_form_type"
    android:textAppearance="?android:attr/textAppearanceLarge"        android:gravity="center"/>

<Spinner
    android:id="@+id/create_form_type_sp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

2 个答案:

答案 0 :(得分:2)

试试这个:

  final LinearLayout textEntryView = (LinearLayout) factory.inflate(R.layout.database_creation_form, null);

答案 1 :(得分:0)

我认为database_creation_form包含一些linearlayout,我们假设它的id = linearLayout。然后,下面的代码将允许您访问它。

LinearLayout mainLinear = (LinearLayout)textEntryView.findViewById(R.id.linearLayout);