基于单击可扩展列表隐藏单个子视图项

时间:2017-05-26 12:01:40

标签: java android expandablelistview

我有一个可消耗的视图列表视图,因为我有一个子视图。在子视图中,我在此删除按钮上有删除按钮,我想更改孩子的布局。

  

我想在点击删除按钮时显示隐藏布局并显示/替换不同的布局,请查看子视图XML的工作情况,但应用所有子视图并替换所有组中的所有子视图。

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res  /android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/inboxChild"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/light_blue"
        android:text="Tb " />
</LinearLayout>

<LinearLayout
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/light_blue"
    android:orientation="horizontal"
    android:visibility="gone">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="15dp"
        android:layout_weight="1"
        android:gravity="center">

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@color/dark_blue"
            android:drawableLeft="@drawable/ic_vol_type_tv_dark"
            android:gravity="center"
            android:padding="5dp"
            android:text="Open"

            android:textColor="@android:color/white"
            android:textSize="16dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="15dp"
        android:layout_weight="1"
        android:gravity="center">

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_centerHorizontal="true"
            android:background="@color/dark_blue"
            android:drawableLeft="@drawable/ic_vol_type_tv_dark"
            android:padding="5dp"
            android:text="Delete"
            android:textColor="@android:color/white"
            android:textSize="16dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="15dp"
        android:layout_weight="1"
        android:gravity="center">

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:background="@color/dark_blue"
            android:drawableLeft="@drawable/ic_vol_type_tv_dark"
            android:gravity="center"
            android:padding="5dp"
            android:text="Flage"
            android:textColor="@android:color/white"
            android:textSize="16dp" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/deleteLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/light_blue"
    android:orientation="horizontal"
    android:visibility="gone">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="15dp"
        android:layout_weight="1"
        android:gravity="center">

        <Button
            android:id="@+id/button5"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_centerHorizontal="true"
            android:background="@color/dark_blue"
            android:drawableLeft="@drawable/ic_vol_type_tv_dark"
            android:padding="5dp"
            android:text="Delete"
            android:textColor="@android:color/white"
            android:textSize="16dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="15dp"
        android:layout_weight="1"
        android:gravity="center">

        <Button
            android:id="@+id/button6"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_centerHorizontal="true"
            android:background="@color/dark_blue"
            android:drawableLeft="@drawable/ic_vol_type_tv_dark"
            android:padding="5dp"
            android:text="Flage"
            android:textColor="@android:color/white"
            android:textSize="16dp" />
    </LinearLayout>
</LinearLayout>

//查看子视图适配器

    @Override
    public View getChildView(final int groupPosition, final int childPosition,
    boolean isLastChild, View convertView, ViewGroup parent) {


        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.inbox_child, null);
        }

        TextView txtListChild = (TextView) convertView.findViewById(R.id.inboxChild);
        final LinearLayout mainLayout = (LinearLayout) convertView.findViewById(R.id.mainLayout);
        final LinearLayout deleteLayout = (LinearLayout) convertView.findViewById(R.id.deleteLayout);


        mainLayout.setVisibility(View.VISIBLE);
        deleteLayout.setVisibility(View.GONE);


        Button delete = (Button) convertView.findViewById(R.id.button2);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                deleteLayout.setVisibility(View.VISIBLE);
                mainLayout. setVisibility(View.GONE);
            }
        });

0 个答案:

没有答案