I have a basic application which gets some data from a JSON file online. It's an array of 6 items. Each item consists of a few integers, strings etc. Only showing 1 string and integer in the list of cards.
When I click on a card. A new activity should be opened and a more detailed view should open. I already made this acitivty without filling in the data. Just to build the layout. But now I'm kind of stuck.
A normal onClick event that starts a new Intent from my main activity is no problem. The problems are that I don't know where and how to implement a onClick method on a button ON the card, while still knowing which card is clicked so I can provide the correct information.
Any ideas on this topic? Been searching all night already but seem to fail every time.
Edit: The 6 items are stored in a List in the main activity. So I just need to get to know the index number of the clicked item so I can read out the right item in the detail view.
Second edit viewHolder click doesn't register any click...
public static class ParkingViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv;
TextView parkingName;
TextView parkingCapacity;
ParkingViewHolder(View itemView) {
super(itemView);
cv = (CardView)itemView.findViewById(R.id.cv);
parkingName = (TextView)itemView.findViewById(R.id.parkingName);
parkingCapacity = (TextView)itemView.findViewById(R.id.parkingCapacity);
}
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "The Item Clicked is: " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
}
}