aycelenozdemir
aycelenozdemir

Reputation: 13

How can I add visited backround or shadow when I clicked on my recyclerView item on Android Studio?

usercafe.java

recyclerView.addOnItemTouchListener(new AuthorizeCafes.RecyclerItemClickListener(getApplicationContext(), recyclerView, new AuthorizeCafes.RecyclerItemClickListener.OnItemClickListener() {
            @Override
                public void onItemClick(View view, int position) {
                cafe = cafeAdapter.getItemName(position);
                Intent intent=new Intent(UserCafe.this, UserProduct.class);
                intent.putExtra("name", cafe.name);
                intent.putExtra("image", cafe.image);
                Toast.makeText(UserCafe.this, cafe.name, Toast.LENGTH_SHORT).show();

                startActivity(intent);
            }

cafe.java

public class Cafe {
public String name;
public String image;


public Cafe(String name,String image) {
    this.name = name;
    this.image = image;

}
public Cafe() {}

cafeadapter

public int getItemCount() {
    return categoryList.size();
}//loop değerleri kadar döndürür

public class ViewHolder extends RecyclerView.ViewHolder {
    //Define textviews
    TextView categorytext;
    ImageView iv_image;`  

I want to make like a background when I clicked for once the cafe's name or image but they coming to usercafe page with recyclerView.

Upvotes: 0

Views: 45

Answers (1)

Ticherhaz FreePalestine
Ticherhaz FreePalestine

Reputation: 2377

You can create a new variable named visited as Boolean.You can do something like this.

This is Cafe.class

public class Cafe {
public String name;
public String image;
public boolean visited;


public Cafe(String name,String image, boolean visited) {
    this.name = name;
    this.image = image;
    this.visited = visited;
}
public Cafe() {}

Once the user click the item. You can update the value.

@Override
public void onItemClick(View view, int position) {
    cafe = cafeAdapter.getItemName(position);
    cafe.setVisited(true);
}

At the ViewHolder, you can custom what you want to change. But for this example. I just change the name for categoryText.

if (visited){
    categoryText.setText("Visited");
} else {
    categoryText.setText(name);
}

Upvotes: 1

Related Questions