Android 拆下两个线性布局';它位于充气机布局内

Android 拆下两个线性布局';它位于充气机布局内,android,parent,android-linearlayout,removechild,layout-inflater,Android,Parent,Android Linearlayout,Removechild,Layout Inflater,我有一个名为Social_form_organization.xml的xml文件,它有两个布局。这个xml文件在一个名为content的布局中膨胀,我们可以通过下面的代码看到它 social\u form\u organization.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/sfo_layout" andr

我有一个名为Social_form_organization.xml的xml文件,它有两个布局。这个xml文件在一个名为content的布局中膨胀,我们可以通过下面的代码看到它

social\u form\u 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>
但是现在,当我点击ImageButton时,我需要删除内容中的两个布局,但我不能

我试着用

    View toRemove = (View) view.getParent();
    ViewGroup vg = (ViewGroup)findViewById(R.id.se_content);
    vg.removeView(toRemove);
但只有当我有一个布局时才有效。在这种情况下,我有两个布局,不工作

我不知道我是否能让你明白。有人能帮我吗?
谢谢

您正在引用两个您提供的布局中不存在的ID:

lLayoutOrganization = (LinearLayout)findViewById(R.id.se_contentOrganization);
se_contentOrganization
在哪里?你的意思是
se_content email

当您尝试删除视图时:

ViewGroup vg = (ViewGroup)findViewById(R.id.se_content);
se_content
在哪里?或者你的意思是
se_content email
?或
sfo_布局

添加

试试这个:

LinearLayout parent = (LinearLayout) findViewById(R.id.se_contentOrganization);
LinearLayout child = (LinearLayout) findViewById(R.id.sfo_layout);
parent.removeView(child);
如果您多次使用Social_form_organization.xml,请尝试:

LinearLayout child = (LinearLayout) view.getParent().getParent(); 
LinearLayout parent = (LinearLayout) child.getParent(); 
parent.removeView(child);

你有什么错误吗?如果是这样,请张贴日志。嗨,山姆。我没有错误。当我点击imagebutton删除内容时,不会发生任何事情,内容也不会被删除。抱歉,错误sam。已经升级。不是se_contentEmail,而是yes se_contentOrganization.Ok,您要删除哪个线性布局
se_contentOranization
?我需要删除两个线性布局。android:id=“@+id/sfo_布局2”和android:id=“@+id/sfo_布局2”。当我尝试在图像按钮视图中单击时,移动=(视图)视图。getParent();ViewGroup vg=(ViewGroup)findViewById(R.id.se_contentOrganization);vg.移除视图(toRemove);不工作(呵呵,我想你的意思是
sfo_布局
sfo_布局2
)我的最新答案应该可以做到这一点,让我知道它是否适合你。山姆,如果你能看到我下面的答案,我很感激:)
LinearLayout parent = (LinearLayout) findViewById(R.id.se_contentOrganization);
LinearLayout child = (LinearLayout) findViewById(R.id.sfo_layout);
parent.removeView(child);
LinearLayout child = (LinearLayout) view.getParent().getParent(); 
LinearLayout parent = (LinearLayout) child.getParent(); 
parent.removeView(child);