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
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 !