Guest User

Untitled

a guest
Aug 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. How to listen for a checkbox in a listview row?
  2. String[] from = new String[] { CallrzDbAdapter.C_NAME,CallrzDbAdapter.C_EMAIL,CallrzDbAdapter.C_PHONE };
  3. int[] to = new int[] {R.id.cName, R.id.cEmail, R.id.cPhone };
  4.  
  5.  
  6. notes = new SimpleCursorAdapter(this,
  7. R.layout.row, cursor, from, to);
  8.  
  9. ListView view =getListView();
  10. view.setHeaderDividersEnabled(true);
  11. view.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  12. view.setOnItemLongClickListener(new OnItemLongClickListener() {
  13.  
  14. @Override
  15. public boolean onItemLongClick(AdapterView<?> arg0, View view,
  16. int position, long arg3) {
  17. Toast.makeText(getApplicationContext(), "Hello"+position+" is clicked ",
  18. Toast.LENGTH_SHORT).show();
  19.  
  20. return false;
  21. }
  22. });
  23.  
  24. //setListAdapter(notes);
  25. setListAdapter(notes);
  26.  
  27. class MyViewBinder implements SimpleAdapter.ViewBinder {
  28. public boolean setViewValue(View view, Object data, String textRepresentation) {
  29. int id = view.getId();
  30. /* handle this particular item from our own view
  31. if (id == R.id.myViewId) {
  32. ((CheckBox) view).setOnItemLongClickListener(...);
  33. ((CheckBox) view).setText(...);
  34. return true;
  35. }
  36. return false;
  37. }
  38. }
  39.  
  40. Checkbox yourCheckbox = (Checkbox) view.findViewById(R.id.your_checkbox_id);
Add Comment
Please, Sign In to add comment