Android ListView Swipe Right and Left to Accept and Reject

前端 未结 6 1160
遥遥无期
遥遥无期 2020-12-05 11:37

I want to develop a list view that when swiped left to right - displays in the left corner an accept (true) icon (non clickable - show just a color change when swiping left

6条回答
  •  -上瘾入骨i
    2020-12-05 12:21

    based on @Pratibha Sarode solution I adapt it as follow with a listview poupulated with a cursoradaptor and a database : In the main activity :

      //-- Attach cursor adapter to the ListView
        lvItems.setAdapter(todoAdapter);
        /////////////////// Swipe Management
        lvItems.setOnTouchListener(new OnSwipeList(AfficList.this,lvItems){
            public void onSwipeRight(int pos) {
                AnnonceDbHandler dbHandler = new AnnonceDbHandler(AfficList.this, null, null, 1);
                String sIdAnn=dbHandler.RechercheIdIndex(pos);
                //Toast.makeText(AfficList.this, "Right ("+pos+") : "+sIdAnn, Toast.LENGTH_SHORT).show();
                dbHandler.deleteAnnonce(sIdAnn, AfficList.this);
                Cursor NewCursor = dbAnnonces.rawQuery("SELECT  * FROM annonces", null);
                todoAdapter.swapCursor(NewCursor);
                lvItems.setAdapter(todoAdapter);
                todoAdapter.notifyDataSetChanged();
            }
            public void onSwipeLeft(int pos) {
                AnnonceDbHandler dbHandler = new AnnonceDbHandler(AfficList.this, null, null, 1);
                String sIdAnn=dbHandler.RechercheIdIndex(pos);
                //Toast.makeText(AfficList.this, "Right ("+pos+") : "+sIdAnn, Toast.LENGTH_SHORT).show();
                dbHandler.deleteAnnonce(sIdAnn, AfficList.this);
                Cursor NewCursor = dbAnnonces.rawQuery("SELECT  * FROM annonces", null);
                todoAdapter.swapCursor(NewCursor);
                lvItems.setAdapter(todoAdapter);
                todoAdapter.notifyDataSetChanged();
            }
        });
    

    It work's great deleting lines with swipe movment !

提交回复
热议问题