230 RecyclerView OnClick |

preview_player
Показать описание
"Learn How To Design + Code A Complete App From Scratch To Playstore"
-~-~~-~~~-~~-~-

This Android video shows how to handle onClick for items in the RecyclerView and how to delete items from RecyclerView adapter on click. Use an onClickListener inside your RecyclerView.ViewHolder or onBindViewHolder method, pass the position using the getPosition method. Delete items from the Adapter using the notifyItemRemoved from RecyclerView.Adapter instead of using notifyDataSetChanged

RECYCLER VIEW CLICK HANDLING TECHNIQUES

OUR WEBSITE

How to LEARN ANDROID from slidenerd?
Follow this-

How to learn JAVA from slidenerd?
Follow this-

How to LEARN JAVASCRIPT from slidenerd?
Follow this-

How to LEARN PYTHON from slidenerd?
Follow this-

OUR SOCIAL LINKS
Follow us on

WHERE TO GET CODE?
Рекомендации по теме
Комментарии
Автор

Here's a suggestion for everyone following these awesome videos. Initiate a Git repository for the project and commit changes to your code at every milestone - for example, both onClickListener call options for the icon. You may then push these to a remote repository such as Github or Bitbucket (free private repositories) so you can quickly go back and see each step. This has helped me a ton. Thanks slidenerd!

opheliadesign
Автор

Thank you! Can't wait for you to show how to handle fragments on click. Keep up the great work!

Grabacr
Автор

Great tutorials man, I think you are one of the best Explaining things.

rapanovela
Автор

Thanks slidenerd you are doing a great job much appreciated

Imu
Автор

like always best tutorial...thanks vivz

fredrickamani
Автор

hi
i have followed your video and try to build a OnClickedListener on both ways, but they all clashed and give ont this.
Attempt to invoke virtual method on a null object reference
what can i do to fix it ?

luckyboy
Автор

Hey Vivz! I need Your help.
im using listview in an app where i would like to allow the user to add or remove items from the list however im unable to find the video where you have detailed this. You mentioned that you have talked about notifydatasetchanged in a previous video.can you share the link?

akhileshmalini
Автор

To those getting a NullPointer Toast error involving the "context" variable, instead of declaring a Private Context context, just use v.getContext() for the first Toast.makeText argument instead.

compeng
Автор

Guys how do I make the app stay with the deleted rows when we re open the app? Please help!

GursimranBedi
Автор

I have searched on SO and many tutorials online, I am having a hard time with functionality that is very basic and should be easy to do but I can't find anyone explaining it. I would like to long click on a RecyclerView item, make it appear different because it is now "selected", and somehow access that selected RecyclerView item in my fragment where I would handle for example a Delete button click to remove that selected item from the list. Any suggestions, a possible tutorial or any information would be helpful. Thank you!

ivandamyanov
Автор

slidenerd In Gmail, Inbox (or any other google apps), the entire navigation bar is scrollable (including the picture on top), but when using the recyclerview, only the list is scrollable, and wrapping everything inside a scrollview makes the list disappear (even if I set the recyclerview to just wrap_content for height). Any way to solve this?

trigien
Автор

If you find when you click on an item and it deletes a different one, you need to add notifyItemRangeChanged(position, getItemCount()) after notifyItemRemoved(position);

NoMotif
Автор

Hi
can you tell me how can i get the data visible in gridview by accessing it from the database on my my cart page as a gridview

ImranAli-etpg
Автор

Hello Vivz, so I came up with a simple way to use the Recycler Adapter through MainActivity by adding onClickListener.

In my MenuAdapter.java:
Instead of:


I did:


In my MainActivity.java:

//NOTE: "***" indicate the important lines I added

public class MainActivity extends ActionBarActivity {

    private DrawerLayout mDrawerLayout;
    ***static View.OnClickListener myOnClickListener;
    ***private static RecyclerView recyclerView;
@Override
    protected void onCreate(Bundle savedInstanceState) {
       
       

        ***myOnClickListener = new MyOnClickListener(this);
        ***recyclerView = (RecyclerView)
...
...
...
}
// I added a private class here. I did not MAKE it static because i wouldn't be able to access somethings like the Drawerlayout in this.

    private class MyOnClickListener implements View.OnClickListener {

        private final Context context;

        private MyOnClickListener(Context context) {
            this.context = context;
        }

        public void onClick(View v) {
            itemNumberToast(v);
            mDrawerLayout = (DrawerLayout)
            mDrawerLayout.closeDrawers();
        }
        private void itemNumberToast(View v) {
            int selectedItemPosition =
            Toast.makeText(v.getContext(), "onClick at " + selectedItemPosition, Toast.LENGTH_SHORT).show();
        }
    }

What do you think of this method? Are there any downsides to this one? Isn't this method more flexible and useful?

Thanks! Please do reply! Your tutorial shave helped me a TON!

yoosuf
Автор

Your videos are so useful! How can I bind the onClickListener to `holder` and not just an element inside `holder`?

balaclava
Автор

Hi
+slidenerd can you tell me how can i get the data visible in gridview by accessing it from the database on my my page as a gridview

ImranAli-etpg
Автор

I couldn't do the last step, calling 'delete' wouldn't let me access the Adapter class from the ViewHolder class. To resolve, make sure you've passed an instance of the Adapter class to the view holder:

GroceryItemAdapter mAdapter;
public MyViewHolder(View itemView, MyAdapter adapter) {
mAdapter = adapter;
...
}

// instead of just 'delete (getAdapaterPosition());'

ukBenuk
Автор

How to use SharedPreferences inside recyclerview for instance in title and passed it to another activity

masbro
Автор

sir can you please make a video on adding each row item dynamically into the recyclerview

rajnikantpandey
Автор

Slidenerd, I have a strange bug on my recyclerview. I have a bunch of CardViews and some have different height because of the text inside them. When I remove a CardView, the next CardView will have the height of the removed one. I use and then Can you help?

pauloferreira