Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to set up a delete button to delete a customer from a table, the customers are displayed in card views using a recycler view so each customer will have their own delete button, the customer information are displayed using textviews. i need to pass the customer id to the delete method i order to search the table for that specific id to delete. how do i pass the data succesfully?

when i click the button in app i get blank screen and it returns to the home screen, if anyone can help me be much appreciated

this is what iver currently got to try and pass the data i need

passing data to method

public void onBindViewHolder(@NonNull MyHolder holder, final int position) {

        holder.idText.setText(String.valueOf(id.get(position)));
        holder.nameText.setText(String.valueOf(name.get(position)));
        holder.surnameText.setText(String.valueOf(surname.get(position)));
        holder.add1Text.setText(String.valueOf(add1.get(position)));
        holder.add2Text.setText(String.valueOf(add2.get(position)));
        holder.add3Text.setText(String.valueOf(add3.get(position)));
        holder.postCodeText.setText(String.valueOf(postCode.get(position)));
        holder.phoneNumberText.setText(String.valueOf(phoneNumber.get(position)));
        holder.emailText.setText(String.valueOf(email.get(position)));
        
        GlobalVars.id = holder.idText.getText().toString();

        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                db.deleteCustomer(GlobalVars.id);
            }
        });
    }


delete method

public long deleteCustomer(String id)
    {
        SQLiteDatabase db = this.getWriteableDatabase();
        ContentValues idValue = new ContentValues();
        idValue.put(CUSTOMER_ID, id);

        return db.delete(TABLE_NAME, "where Customer_ID = " + idValue, null);
    }



What I have tried:

holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                db.deleteCustomer(GlobalVars.id);
            }
        });
Posted
Comments
David Crow 1-May-21 23:40pm    
Call setTag() in the adapter's onBindViewHolder() method, and then call getTag() when you need info for a particular item.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900