Forum Xamarin.Android

RecyclerView Button only recognized on the first item

Newbie here - currently trying to get a button within each card working, and the actions for each click is registering for the first item in the List only.
My adapter is currently working with an ItemClick, that returns the position of which card is being interacted with, but the OnItemClick within the same activity only registers the action within the first card. See below:

public class AP_EM_Activity : Activity
// Loads the Cards
RecyclerView mRecyclerView;
// Layout manager that shows the cards in RecyclerView
RecyclerView.LayoutManager mLayoutManager;
// Adapter for access to data
CVBFItemListAdapter mAdapter;
// array list managed by adapter
AP_EM_ItemList mItemList;
protected override async void OnCreate(Bundle savedInstanceState)
//Create Menu List
mItemList = new AP_EM_ItemList();

        //Set View

//Set up layout manager to view all cards on recycler view
mRecyclerView = FindViewById(Resource.Id.recyclerView);
mLayoutManager = new LinearLayoutManager(this);
//Menu List Adapter
mAdapter = new CVBFItemListAdapter(mItemList);
//Put adapter into RecyclerView

        //Card Clicked
        mAdapter.ItemClick += OnItemClick;

void OnItemClick(object sender, int position)
modifyi = FindViewById(Resource.Id.btn_cardModify);
modifyi.Click += delegate
Console.WriteLine("modify pressed");

        Android.Widget.Toast.MakeText(this, "Card clicked.", Android.Widget.ToastLength.Short).Show();

What's weird id that the "Card clicked" toast message occurs with every card. I believe it's how I'm using the click, but I'm unsure of where and how to use the setOnClickListener, or whether that would work for cardviews.

Any help is appreciated, thanks guys.


  • ParthaSarathyParthaSarathy USMember ✭✭

    Changed the code like this and try...

    void OnItemClick(object sender, AdapterView.ItemClickEventArgs e)
    int Position=e.Position;
    Code for get Particular data from list
    mItem = mItemList[e.Position] or mItemList[Position]


  • MirNiazMirNiaz USMember

    e.Position would only give me the position of the information, not allow me to click into it.
    It's also stating I need overload methods to handle the EventViewer.

    At this point, the below is still only allowing me to hit the first card.

    void OnItemClick(object sender, int position)
    Button editItem = FindViewById(Resource.Id.btn_cardModify);
    dialog_AP_EM_Modify modifyMenu = new dialog_AP_EM_Modify();
    modifyMenu = new dialog_AP_EM_Modify();

            editItem.Click += delegate
                FragmentTransaction transaction = FragmentManager.BeginTransaction();
                Console.WriteLine("modify clicked.");
                modifyMenu.Show(transaction, "something");
                Android.Widget.Toast.MakeText(this, "Modify Item Clicked.", Android.Widget.ToastLength.Short).Show();
            Android.Widget.Toast.MakeText(this, "Card Clicked.", Android.Widget.ToastLength.Short).Show();
  • ParthaSarathyParthaSarathy USMember ✭✭
    edited March 2016

    Please update your Full Code, still i am not sure what is your problem.

    do you want perform click action for Button inside Grid?
  • I have a RecyclerView in the RecyclerView Adapter i attached a cardview layout in the cardview have a button like

    in recyclerview each fragment have a diffrent-diffrent items as per item cardview genereted how can i handle each button click event
    Any solution for this question ??

Sign In or Register to comment.