Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 13th, 2012  |  syntax: None  |  size: 1.78 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. listview using customAdapter
  2. public class customAdapter extends SimpleCursorAdapter {
  3. Context c;
  4. private ToDo ob;
  5. public customAdapter(Context context, int layout, Cursor c, String[] from,
  6.         int[] to) {
  7.     super(context, layout, c, from, to);
  8.     this.c = context;
  9.     //lv.getListView();
  10.     this.ob=(ToDo)context;
  11.  
  12. }
  13.  
  14.  
  15.  
  16. @Override
  17. public View getView(int position, View convertView, ViewGroup parent) {
  18.  
  19.      long id=getItemId(position);//rowid
  20.  
  21.     View v = convertView;
  22.  
  23.     LayoutInflater vi =                   (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  24.     v = vi.inflate(R.layout.simple, null);
  25.  
  26.     TextView tv1= (TextView)v.findViewById(R.id.Text1);
  27.  
  28.     TextView tv2= (TextView)v.findViewById(R.id.Text2);
  29.  
  30.     Button btn = (Button) v.findViewById(R.id.delete1);
  31.  
  32.     btn.setTag(id);
  33.  
  34.      System.out.println(btn.getTag());
  35.  
  36.  
  37.  
  38.     btn.setOnClickListener(new View.OnClickListener() {
  39.         @Override
  40.         public void onClick(View v) {
  41.             Log.i("ToDo", "delete Row");
  42.             long id = (Long) v.getTag();
  43.     ob.DeleteRow( id);   //moment control reaches this line process terminates
  44.             Log.i("ToDo", "delete after");
  45.                     notifyDataSetChanged();
  46.             Log.i("ToDo", "delete ");
  47.         }
  48.  
  49.     });
  50.     v.setLongClickable(true);
  51.     return v;
  52. }
  53.  
  54. }
  55.        
  56. private void fillData() {
  57.     Cursor c = mDbHelper.fetchAll();
  58.     startManagingCursor(c);
  59.          String[] from = new String[] { ToDoDBAdapter.KEY_TITLE,
  60.             ToDoDBAdapter.KEY_CREATED_ON };
  61.      int[] to = new int[] {R.id.Text1, R.id.Text2 };
  62.  
  63.     // to display list and time
  64.  
  65.  
  66.      Log.i("ToDo", "Created custom adapter");
  67.  
  68.        this.lv = getListView();
  69.       this.todo = new customAdapter(this,R.layout.simple, c, from,to);
  70.       lv. setAdapter(todo);    
  71.  
  72.  
  73. }