Android Cardview Menu Item Click to opens Different Activity - java

I am having a hard time figuring this one out. I am creating an Android app where the user (once logged in) sees an activity with a cardview list inside a recycler view.
I want the user to be able to click item on a card and go to a different activity. If you click menu item on card 1 you must go to the activity for game 1. If you click menu item on card 2 you must go to the activity for game 2. Etc...

In your adapter's ViewHolder class add following:
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener(){
// Start your activity
});
}
Create switch case to open different activities and then get recycler view position on the basis of that and provide different URL for each cards.

Related

Recycler view adapter remove items

I have two activities: HomePage and MyFavorites. Both have recycler views with items (similar to facebook posts) each item has a button, when you click on it, the item will be shown in the recycler view for MyFav activity. The code for when the button is clicked is in the Adapter class for the recycler view (both activities use the same adapter). Now when a user click on the button for the second time (while the user is in MyFav activity) it means that this specific item should be removed from the recycler view in MyFav activity, but when the button is clicked for a second time while the user is using/opening the HomePage activity the item shouldn’t be removed, the button will turn from red to white ONLY . How can i remove the item only from the recycler view in MyFav activity without removing it from the HomePage activity (since both use the same adapter for their recycler view) without making a new adapter?
If i create separate adapter class for each activity, is it good practice? Since the same code will be duplicated twice with minor changes.
Note: the button (Fav button) is a checkbox with a heart shaped icon, the color is initially white, it will turn red when clicked for the first time, and white when clicked again and so on..

Android. How to show 2 items in recycler view and then add one item on every button click

I want to show 2 items by default and add items in recycler view when we click button in main activity. Those item contains edittext so I have to get the data from edittext in my main activity.
Basically you have to create two different ViewType/Layouts to implement this.
Sharing related links below..
https://www.geeksforgeeks.org/how-to-create-recyclerview-with-multiple-viewtype-in-android/
How to create RecyclerView with multiple view types
For adding items to Recycler view when you click in a button you should add the item in the list and notify adapter that new item added at the end of the recyclerview using notifyItemInserted()
and for the other question for getting the edittext value from the adapter to the activity you can create a callback interface that implemented in the activity and pass the reference to the adapter and fire it from adapter when Edittext value is changed

Recycler View Adapter looping objects in pairs

hello I'm sorry for the ambiguous nature of my question but this is the easiest way I can explain the problem. Okay so I have an adapter which pulls parsed json data from mysql database and places each json object in a cardview and I have a recyclerview where these cardviews are displayed. Each cardview has a button with an onClick method to change color of button when it is clicked. This works fine except that the action performed on the first cardviews button is also performed on the seventh cardview, action of second cardview performed on the eighth cardview and that's how it continues. In a nutshell when button1 in cardview one is clicked, color of button1 in cardview 1,7,13,19,etc changes. That is looping through pairs of 6. Any idea how to resolve this please.
I solved it by implementing
#Override
public int getItemViewType(int position){
return position;
}

How to handle Swipe and Click event in the same cardview - Android

I am working on a android app, which has card swiping functionality like Tinder. In each cards, I'm having a imageview, which on click, opens in full screen. My problem is when I try to swipe, the image view considers it as a click event and opens the image in full screen.
I'm having my code for imageview onclick in the card swipe adapter and the code for swipe in the main activity that uses the card swipe adapter. How can I restrict the child view from consuming the parent's event?

How to make checkbox in gridview visible only when menu item is clicked in fragment?

I am developing a multi select gridview of pictures from gallery.
I have included imageview and checkbox as each grid item.
I need to make the checkbox visible only when i click the select label in actionbar (menu item). Please advice how I can make it work. I am new to android development and any help is appreciated.
For any View, you can control whether or not it is visible by using the setVisibility(int) method. The int passed should be one of three values (taken from this question)
View.VISIBLE (0): the view is visible.
View.INVISIBLE (1): The view is invisible, but it still takes up
space for layout purposes.
View.GONE (2): the view is gone. Completely hidden, as if the view
had not been added
To make that change, you'll need a listener for when the fragment is clicked. It may look something like this:
myFragment.setOnClickListener( new onClickListener(){
#Override
public void onClick(View v) {
myCheckBox.setVisiblity(View.VISIBLE);
}
});

Categories

Resources