我有一个名为socio_form_organization.xml的xml文件,它有两个布局。此XML文件在布局名为内容夸大,我们如何通过代码见下文在inflater布局中删除两个LinearLayout
socio_form_organization.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sfo_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_tile"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sfo_layout2"
android:layout_width="wrap_content"
android:layout_height="51dp"
android:background="@drawable/background_tile"
android:baselineAligned="true"
android:orientation="horizontal">
<Button
android:id="@+id/sfo_btOrganization"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:hint="@string/sfo_btOrganization" />
<EditText
android:id="@+id/sfo_etEmpresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:layout_weight="0.14"
android:hint="@string/sfo_etEmpresa"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<ImageButton
android:id="@+id/sfo_ivRemove"
style="?android:attr/buttonStyleSmall"
android:layout_height="60dp"
android:layout_width="50dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginRight="5dp"
android:onClick="onClick"
android:background="@android:color/transparent"
android:src="@drawable/tb_no_delete" />
</LinearLayout>
<EditText
android:id="@+id/sfo_etTitulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="65dp"
android:layout_marginRight="55dp"
android:layout_marginTop="2dp"
android:layout_weight="0.14"
android:hint="@string/sfo_etTitulo"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
</LinearLayout>
布局,其中充气时socio_form_organization.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/se_contentOrganization"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:background="@drawable/background_tile"
android:orientation="vertical" >
<include
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
layout="@layout/socio_form_organization" />
在我的班级我做通胀
LayoutInflater inflaterOrganization=
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout organization =
(LinearLayout)inflaterOrganization.inflate(R.layout.socio_form_organization, null);
LinearLayout lLayoutOrganization;
lLayoutOrganization = (LinearLayout)findViewById(R.id.se_contentOrganization);
lLayoutOrganization.addView(organization);
但现在需要删除内容中的两个布局,当我点击ImageButton,但我不能。
我尝试用
View toRemove = (View) view.getParent();
ViewGroup vg = (ViewGroup)findViewById(R.id.se_content);
vg.removeView(toRemove);
但只有当我有一个布局工作。在这种情况下,我有两个布局,不工作。
我不知道我是否能让你明白。任何人都可以帮助我? 感谢
您是否收到任何错误?如果是这样,请发布logcats。 – Sam 2012-07-17 16:36:58
Hy Sam.I没有错误。只要当我点击图像按钮删除内容膨胀没有任何反应,内容不会被删除。 – 2012-07-17 16:43:01