how to remove SwipeExecuteBehavior for some item in one RadListView

3 posts, 0 answers
  1. Xiaoming
    Xiaoming avatar
    9 posts
    Member since:
    Oct 2011

    Posted 29 Jul 2015 Link to this post

    I want to RadListView's some items don't add SwipeExecuteBehavior.I use listview.remove(SwipeExecuteBehavior)method,but when i swiped,it occured some error which I can't deal with.This is the error 

     java.lang.UnsupportedOperationException: Behavior is not attached to RadListView. Use RadListView's addBehavior method to attach it.
                at com.telerik.widget.list.ListViewBehavior.owner(ListViewBehavior.java:148)
                at com.telerik.widget.list.SwipeExecuteBehavior$1.run(SwipeExecuteBehavior.java:337)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:135)
                at android.app.ActivityThread.main(ActivityThread.java:5254)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

  2. Xiaoming
    Xiaoming avatar
    9 posts
    Member since:
    Oct 2011

    Posted 29 Jul 2015 in reply to Xiaoming Link to this post

    @Override
    public void onBindSwipeContentHolder(ListViewHolder holder, int position) {
    super.onBindSwipeContentHolder(holder, position);
    if (allMainListViewItem.get(position).getEventType() == 4) {
    try {
    mSwipeExecuteBehavior.removeListener(mMainSwipeListener);
    mRadListView.removeBehavior(mSwipeExecuteBehavior);
    } catch (Exception ex) {
    ex.printStackTrace();
    Toast.makeText(mContext, "日期不能滑动", Toast.LENGTH_SHORT).show();
    } finally {
    Toast.makeText(mContext, "日期不能滑动", Toast.LENGTH_SHORT).show();
    }

    }
    }

    This is  the code in application,I want to the eventType == 4's item do't swipe

  3. DevCraft banner
  4. Todor
    Admin
    Todor avatar
    778 posts

    Posted 30 Jul 2015 Link to this post

    Hi Xiaoming,

    Thank you for your question.

    Yes, the exception that you get is caused by the fact that you remove the behavior. What you can do is, to override canSwipe in your adapter:

    @Override
    public boolean canSwipe(int position) {
        return super.canSwipe(position) && allMainListViewItem.get(position).getEventType() != 4;
    }

    I hope this information helps.

    Regards,
    Todor
    Telerik
    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
Back to Top