How to delete custom Adapter elements using a custom model

Custom Adapter elements never disappear!

Even if I try to remove the Adapter element using a custom model with adapter.remove (item), it does not disappear.

Bad example


@Override
public void onItemClick(final AdapterView<?> adapterView, View view, final int i, long l) {
            OriginalItem item = (OriginalItem) mItemAdapter.getItem(i);
            mItemAdapter.remove(item);
            list.setAdapter(mItemAdapter);
}

This will not be deleted.

What should I do!

So, implement the delete function in your custom Adapter class.

ItemAdapter.java



//abridgement

public void delete(int pos){
        itemList.remove(pos);
}

//abridgement

The ItemList that holds the elements of the custom Adapter is of type ArrayList <>, so you can delete it with position.

All you have to do is call this.

Implementation example


@Override
public void onItemClick(final AdapterView<?> adapterView, View view, final int i, long l) {
            mItemAdapter.delete(i);
            list.setAdapter(mItemAdapter);
}

Recommended Posts

How to delete custom Adapter elements using a custom model
How to delete a controller etc. using a command
How to execute a contract using web3j
How to sort a List using Comparator
How to return a value from Model to Controller using the [Swift5] protocol
[Rails] How to create a graph using lazy_high_charts
[Ethereum] How to execute a contract using web3j-Part 2-
How to generate a primary key using @GeneratedValue
How to make a factory with a model with polymorphic association
How to delete a new_record object built with Rails
How to convert A to a and a to A using AND and OR in Java
[Rails] How to install a decorator using gem draper
How to delete child elements associated with a parent element at the same time
How to delete BOM (UTF-8)
How to insert a video
How to create a method
How to authorize using graphql-ruby
[For Ruby beginners] Explain how to freely delete array elements!
[Rails] How to delete images uploaded by carrierwave (using devise)
How to output array values without using a for statement
How to join a table without using DBFlute and sql
How to register as a customer with Square using Tomcat
How to create a jar file or war file using the jar command
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
How to run a mock server on Swagger-ui using stoplight/prism (using AWS/EC2/Docker)
How to make a Java container
[Rails 6] How to create a dynamic form input screen using cocoon
How to delete only specific data from data created using Form object
How to sign a Minecraft MOD
How to make a JDBC driver
[Java] How to create a folder
How to write a ternary operator
[Swift] How to send a notification
How to make a splash screen
How to make a Jenkins plugin
How to rename a model with foreign key constraints in Rails
How to make a Maven project
[Beginner] How to delete NO FILE
How to add the delete function
[Swift5] How to communicate from ViewController to Model and pass a value
How to make a Java array
How to make a groundbreaking diamond using Java for statement wwww
How to build CloudStack using Docker
How to implement a slideshow using slick in Rails (one by one & multiple by one)
How to build a Ruby on Rails environment using Docker (for Docker beginners)
[Java] How to get to the front of a specific string using the String class
[Java] [For beginners] How to insert elements directly in a 2D array
[Xcode] How to add a README.md file
How to make a Java calendar Summary
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
Item 87: Consider using a custom serialized form
How to use custom helpers in rails
How to delete the wrong migration file
[Rails] How to upload images using Carrierwave
[Basic] How to write a Dockerfile Self-learning ②
How to insert a video in Rails
How to delete the migration file NO FILE
[Java] How to calculate age using LocalDate
[Introduction to Java] How to write a Java program
How to create a Maven repository for 2020