How to pass data from recyclerview adapter to fragment and what i have to write the code in fragment to receive data.I have already check the links in this website but unfor
You have two options;
Using SharedPreferences:
Context myContext = exampleViewHolder.itemView.getContext()
SharedPreferences.Editor editor = getSharedPreferences("DeviceToken", MODE_PRIVATE).edit();
editor.putString("YourKeyNameHere", currentItem.getmText()); // or add toString() after if needed
editor.apply();
To get:
SharedPreferences prefs = getSharedPreferences("DeviceToken", MODE_PRIVATE);
String deviceToken = prefs.getString("YourKeyNameHere", null); // get it here
Using Intent: (If you want to start the another Activity when you pass the data)
Intent intent = new Intent(myContext , SignoutActivity.class);
intent.putExtra("EXTRA_TEXT", currentItem.getmText());
startActivity(intent); // if needed, add myContext before starting myContext.startActivity...
To get:
String extraText = getIntent().getStringExtra("EXTRA_TEXT");