Getting item from underlying button in StickySwipe

3 posts, 0 answers
  1. mitch
    mitch avatar
    4 posts
    Member since:
    Aug 2010

    Posted 11 Nov 2016 Link to this post

    I have used the example from http://docs.telerik.com/devtools/android/controls/listview/behaviors/listview-behaviors-swipeactions to create a sticky swipe, on the left when I swipe there is a button and on the right when I swipe there is a button. 

    How would one go about identifying the item in which the button was called for. So with a swipe action I can get the item by looking at the position of the swipe,  however is there a way to detect a button in the underlying view that is exposed when swiped, and then tie it to the parent 'swiped' item?

    The goal is to make a button that says "Archive" and only on click handle the archive of that item. I can get the archive button to fire, but I can't figure out what the item is to archive. 

  2. Deyan
    Admin
    Deyan avatar
    2080 posts

    Posted 15 Nov 2016 Link to this post

    Hello John,

    Thanks for writing.

    If I understand you correctly, we have an example in our SDK repository that demonstrates this. Here's a code snippet:

    @Override
           public void onBindSwipeContentHolder(final ListViewHolder viewHolder, final int position) {
               final EmailMessage currentMessage = (EmailMessage)getItem(position);
               MySwipeContentViewHolder swipeContentHolder = (MySwipeContentViewHolder)viewHolder;
               swipeContentHolder.action1.setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View v) {
                       Toast.makeText(((MySwipeContentViewHolder) viewHolder).itemView.getContext(), currentMessage.title + " successfully archived.", Toast.LENGTH_SHORT).show();
                       sab.endExecute();
                   }
               });
     
               swipeContentHolder.action2.setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View v) {
                       remove(position);
                       Toast.makeText(((MySwipeContentViewHolder) viewHolder).itemView.getContext(), currentMessage.title + " successfully deleted.", Toast.LENGTH_SHORT).show();
                       sab.endExecute();
                   }
               });
           }

    As you can see, we create handlers for the Click event of the buttons in the onBindSwipeHolder callback. In these handlers we have access to the index of the item in question.

    Let me know if that doesn't work for you.

    Regards,
    Deyan
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. mitch
    mitch avatar
    4 posts
    Member since:
    Aug 2010

    Posted 19 Nov 2016 in reply to Deyan Link to this post

    Thanks!
Back to Top