user10013769
user10013769

Reputation:

Delete an item from the list view

I have a list view which i am using to show notifications in a webview.I have added an imagebutton to delete the notification.I set onclick function in the xml file to delete the view,But after deleting it leaves a blank space,I use this method given below,My XML file is `

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LayoutNotifi"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="7dp"
    android:paddingBottom="7dp"
    android:padding="5dp">
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Notification_ListView">
        <TextView
            android:id="@+id/tvNotifi_Name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="normal"
            android:textColor="#ffffff"
            android:textSize="14sp"
            android:maxWidth="280dp"
            android:minWidth="310dp"
            android:layout_marginRight="1dp"
            android:layout_marginBottom="2dp"
            />


        <ImageButton
            android:id="@+id/notification_delete_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/close"
            android:onClick="DeleteNotification"
            android:clickable="true"
            android:minHeight="10dp"
            android:paddingBottom="2dp"
            />
    </LinearLayout>
</LinearLayout>

` onclick function on notification_delete_button

  View viewp=findViewById(R.id.LayoutNotifi);
        view= (View) view.getParent();
        view= (View) view.getParent();
        view.setVisibility(view.GONE);

Upvotes: 0

Views: 57

Answers (2)

user10013769
user10013769

Reputation:

I have solved the issue, I wrote this in the notificationAdapter's getView function and worked fine.

deleteButton=view.findViewById(R.id.notification_delete_button);
         deleteButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 listNotifi.remove(position);
                 notifyDataSetChanged();
             }
         });

Upvotes: 1

kelalaka
kelalaka

Reputation: 5636

Try after VIEW.GONE

if (getParent() instanceof View)
    ((View) getParent()).invalidate();

Upvotes: 0

Related Questions