2012-04-11 137 views
1

我將如何從此對話框中刪除視圖?我知道我可以從 LinearLayout.removeView(id)(LinearLayout.removeView(View))中刪除一個視圖,所以如果有人能告訴我如何獲得(LinearLayout)R.layout.database_creation_form,那也不錯。我使用Android的SDK V7android從對話框中刪除視圖?

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(); 
} 

XML爲database_creation_form:

<?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> 
+0

你可以發佈xml for database_creation_form嗎? – MikeIsrael 2012-04-11 05:55:58

+0

@Mikelsrael剛加了 – ddan 2012-04-11 06:03:50

回答

2

試試這個:

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

完美...謝謝 – ddan 2012-04-11 06:08:27

0

我會假設,database_creation_form包含somekind的的linearlayout,讓我們假設它的id = linearLayout。然後下面的代碼將允許您訪問它。

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