I pass data from my RecyclerView Adapter to my MainActiviy. I also use an interface in the Adapter to capture the CardView item position in the MainActivity's onItemClick() and pass that position to a new Activity (CardViewDetails) using an intent. Problem is the CardViewDetails loads the wrong CardView. How do I use the CardView "position" to launch the correct CardView? What am I missing here?
MainActivity
...
public void passDataFromAdapter(Bundle bundle) {
data = bundle.getString("spantimeinhours");
data2 = bundle.getLong("timeinhours");
}
// This method works with an interface in the Adapter to capture the
// CardView item position.
@Override
public void onItemClick(int position, final View view) {
Intent intent = new Intent(this,Details.class);
intent.putExtra("adapterSpanTimeInHours",data);
intent.putExtra("adapterTimeInHours",data2);
startActivity(intent);
}
Details
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
Bundle extras = getIntent().getExtras();
msgFromAdapter = extras.getString("adapterSpanTimeInHours");
msg2FromAdapter = extras.getLong("adapterTimeInHours", 0);
}
Adapter
public class MyRecylerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private void passDataFromAdapter(Bundle bundle) {
if (context == null)
return;
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.passDataFromAdapter(bundle); // this method must be implemented inside `MainActivity`
}
}
}