logo
down
shadow

Deleting an item from RecyclerView + SQLite


Deleting an item from RecyclerView + SQLite

By : anshu
Date : November 22 2020, 04:01 AM
will help you you are giving position for delete, it's not necessary to id will be same as per adapter position.
try this :
code :
crossImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 Booking booking = bookings.get(getAdapterPosition());
                 datatype id = booking.getId();
                  removeAt(getAdapterPosition(),id);
            }
        });

public void removeAt(int position, dataType id) {
    bookings.remove(position);
    notifyItemRemoved(position);
    notifyItemRangeChanged(position, bookings.size());

    DBHelper.delete(id);
}


Share : facebook icon twitter icon
Item from SQLite database not deleting within RecyclerView

Item from SQLite database not deleting within RecyclerView


By : Meghana
Date : March 29 2020, 07:55 AM
This might help you You are trying to delete by passing the value of the current item position. Of course it won't work! You need to try to get the item by its ID or by the name it has within the RecyclerView, the latter of which means that no item within your database and RecyclerView can have the same name. Try this within your database class:
code :
public boolean deleteList(String name) {
    return db.delete(DATABASE_TABLE, KEY_NAME + "=" + name, null);
}
App crashes while deleting an item from Recyclerview

App crashes while deleting an item from Recyclerview


By : Sukumar Nagarajan
Date : March 29 2020, 07:55 AM
hop of those help? Remove the return statement from if (getTask(position).isDone()) { and put the AlertDialog in the else-clause of that if, as seen below.
code :
holder.deleteImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getTask(position).isDone()) {
                removeTask(position);
                notifyDataSetChanged();

            }else {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
                alertDialog.setTitle("Confirm Delete?");
                alertDialog.setMessage("Do you want to delete the task you created?");
                alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                       dialog.cancel();
                       removeTask(position);
                    }
                });
                alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                       dialog.cancel();
                    }
                });
                alertDialog.show();
            }
        }
});
After deleting item, RecyclerView does not update

After deleting item, RecyclerView does not update


By : Mike
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I think the issue might be the reference to List is not updated in your adapter.
If you look at this code in your presenter:
code :
@Override
public List<TransactionListItem> getAllTransactionItems() {
    List<ProductStockRecord> productStockRecordList = getRealmDataManager().getAllProductStockRecords();

    List<TransactionListItem> transactionListItems = new ArrayList<>();
    // preprocess transactions here

    return transactionListItems;
}
I am getting issue while deleting an item from RecyclerView

I am getting issue while deleting an item from RecyclerView


By : Russel McConnell
Date : March 29 2020, 07:55 AM
Hope this helps It is because you're trying to delete some items with List.remove(position) sequentially. You're probably deleting the same item position with your following code:
code :
asset_type.remove(position);
asset_count.remove(position);
asset_value.remove(position);
AssetDetailsActivity.assetValueId.remove(position);
AssetDetailsActivity.assetCountId.remove(position);
AssetDetailsActivity.assetTypeId.remove(position);
public class YourAdapter extends
    RecyclerView.Adapter<YourAdapter.ViewHolder> {

    ..

    private List<YourDatum> mData;

    public YourAdapter(List<YourDatum> data) {
        mData = data;
    }
}
public class YourActivity extends AppCompatActivity {

     ArrayList<YourDatum> mData;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         // ...

         // assuming that createInitializeData(10) will create 10 data
         mData = createInitializeData(10);

         // Now we're passing the data to adapter.
         YourAdapter adapter = new YourAdapter(mData);
         ...
     }
}
asset_type.remove(position);
asset_count.remove(position);
asset_value.remove(position);

// the following is not needed because it's incorrect
// AssetDetailsActivity.assetValueId.remove(position);
// AssetDetailsActivity.assetCountId.remove(position);
// AssetDetailsActivity.assetTypeId.remove(position)
RecyclerView does not update after deleting an item from sqlite?

RecyclerView does not update after deleting an item from sqlite?


By : Yuvraj Garg
Date : March 29 2020, 07:55 AM
around this issue Remove data from both from your arraylist and from database and than notify your list will update.
or
Related Posts Related Posts :
  • Extracting data from HTML and formatting the output
  • SOLR documentCache JMX metrics clarification
  • Limiting Wildfly 14 Two-Way SSL to specific clients
  • How do I get Min and max values to only print when "year" is entered?
  • Hashmap can't loop - getKey() method not found - Using Java 8
  • Android Studio - Create an EditText with a click of a button
  • Mockito Test not invoking verify() method
  • Wrap method implementations of Java interfaces
  • Remediating dynamic SQL into prepared statements
  • Where do X and Y start at in swing windows
  • java code with files work from eclipse but dont work from cmd
  • Return page object from JPA query
  • I can't figure out why this code in my APCS multiple choice book returns 19
  • How to save data between methods
  • I'm trying to install Apache Gobblin. How can I install it using Gradle?
  • Spring Data Sorting Array or Set into Pageable
  • Question about the Java documentation and its implementation
  • How to make a JButton that when pressed it does a new action
  • Java hibernate No validator could be found for boolean
  • Making a POJO Thread Safe
  • Save the data of a text file in a arraylist
  • Sort a List<String[]> by indices using Comparator
  • Overloading in Java for user input?
  • Unable to format timestamp as YYYY-MM-DD HH:mm:ss in java
  • Access SQLite Helper From Adapter
  • How to stream a csv file with header to a HashMap<String, Double> in Java?
  • can't get go daddy ssl certificate to work with spring boot
  • ResourceBundle can't find BaseName gradle project java
  • Java; Jackson; Parsing the array of array json string
  • Java - map key lookup ignoring case
  • Jackson deserialize map null values to empty string
  • Anyone knows why setCount() is not working in twitter4j?
  • Object Visibility in a Multi-threaded Program in Java
  • Can't store and load an arraylist in an object file
  • convert a string number starts with `00` to `+` in java
  • Java - avoiding NonSuchElementException using ConcurrentLinkedDeque
  • Converting Immutable to mutable list Java
  • Getting nosuchmethod exception
  • How to get MQTT subscriptions
  • Android Google Sign in Exceptions
  • JavaFX - method that waits for user input
  • Replacing values for a particular key in treemap changes values for every key
  • This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter th
  • Kafka: consume all messages on demand
  • Notify what text was changed in textview
  • Tinkerpop/Gremlin: select vertices together with outgoing edge count
  • transform a list of objects into a list of integers that pass a check
  • Why this java code is showing strange behavior?
  • Maven Project classes not compiling
  • Edit image to make text more clear opencv
  • Android Spinner nullpointer
  • Add result to int array every time you finish counting the occurrence
  • Android import java library
  • How to use LDAP Authentication in a corporate environment
  • adding item during iteration in java special usecase
  • How can I sort a map with string key? like (1 foo , 2 foo)
  • How to test an implementation of TLS based on SSLEngine?
  • Sorting a Linked List in alphabetical order
  • Can't make more than one request on java.net.http.HttpClient or will receive: javax.net.ssl.SSLHandshakeException
  • Java logic - strange things happening in while loop
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org