How to do swipe to delete cardview in android using support library -


नमस्ते मैं कार्ड विडियो कार्यक्षमता को प्राप्त करने के लिए सहायता पुस्तकालय android.support.v7.widget.CardView का उपयोग कर रहा हूं। मेरे एंड्रॉइड ऐप में मैं इसे भी कार्यक्षमता को हटाने के लिए स्वाइप प्राप्त करना चाहता हूं।

  & lt; android.support.v7.widget.CardView xmlns: card_view = "http://schemas.android.com/apk / रेस-ऑटो "एंड्रॉयड: आईडी =" @ + id / card_view "एंड्रॉयड: layout_gravity =" केन्द्र "एंड्रॉयड: layout_width =" 200dp "एंड्रॉयड: layout_height =" 200dp "card_view: cardCornerRadius =" 4dp "& gt; & Lt; TextView एंड्रॉइड: id = "@ + id / info_text" एंड्रॉइड: layout_width = "match_parent" एंड्रॉइड: layout_height = "match_parent" / & gt; & LT; /android.support.v7.widget.CardView>  

इसमें कार्यक्षमता को हटाने के लिए कड़ी चोट कैसे प्राप्त करें?

अग्रिम धन्यवाद।

मुझे ऐसा करने के लिए अनुकूलित किया गया है।

एक वर्किंग नमूना आवेदन के साथ, और के होते हैं:

  • है कि घटनाओं को छूने के लिए सुनता है और पता लगाता है एक आइटम Swiped किया जा रहा है जब RecyclerView.OnItemTouchListener का एक उपवर्ग
  • >

इसके इस्तेमाल के लिये GitHub पर निर्देशों का पालन करें, या सिर्फ अपनी परियोजना के लिए कक्षा कॉपी और इस तरह इसका इस्तेमाल:

  @Override संरक्षित शून्य onCreate (बंडल savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); एमआईटीम्स = नया अर्रेलिस्ट & lt; & gt; (30); के लिए (इंट आई = 0; आई & lt; 30; i ++) {mItems.add (स्ट्रिंग। प्रारूप ("कार्ड नंबर% 2d", i)); } MAdapter = नया कार्डविएएडएप्टर (एमआईटीम्स); MRecyclerView = (रिसाइकिलर विज) खोज ViewById (R.id.recycler_view); MRecyclerView.setLayoutManager (नई LinearLayoutManager (यह)); mRecyclerView.setAdapter (mAdapter); SwipeableRecyclerViewTouchListener swipeTouchListener = नए SwipeableRecyclerViewTouchListener (mRecyclerView, नई SwipeableRecyclerViewTouchListener.SwipeListener () {@Override सार्वजनिक बूलियन canSwipe (पूर्णांक स्थिति) {return true;} @Override सार्वजनिक शून्य onDismissedBySwipeLeft (RecyclerView recyclerView, [] reverseSortedPositions int) {(पूर्णांक पद के लिए: reverseSortedPositions ) {mItems.remove (स्थिति); mAdapter.notifyItemRemoved (स्थिति);} mAdapter.notifyDataSetChanged ();} @Override सार्वजनिक शून्य onDismissedBySwipeRight (RecyclerView recyclerView इंट [] reverseSortedPositions) { के लिए (इंट की स्थिति: रिवर्सरेटेड पोशन) {mItems.remove (स्थिति); mAdapter.notifyItemRemoved (स्थिति); } MAdapter.notifyDataSetChanged (); }}); mRecyclerView.addOnItemTouchListener (swipeTouchListener); }  

Comments

Popular posts from this blog

python - Strange behavior using PyQt4's 'pyqtSlot' decorator before another decorator -

c# - UnhandledExceptionMode.ThrowException for AppDomain.UnhandledException -

c# - Process.Kill() returns access denied -