Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- listview using customAdapter
- public class customAdapter extends SimpleCursorAdapter {
- Context c;
- private ToDo ob;
- public customAdapter(Context context, int layout, Cursor c, String[] from,
- int[] to) {
- super(context, layout, c, from, to);
- this.c = context;
- //lv.getListView();
- this.ob=(ToDo)context;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- long id=getItemId(position);//rowid
- View v = convertView;
- LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- v = vi.inflate(R.layout.simple, null);
- TextView tv1= (TextView)v.findViewById(R.id.Text1);
- TextView tv2= (TextView)v.findViewById(R.id.Text2);
- Button btn = (Button) v.findViewById(R.id.delete1);
- btn.setTag(id);
- System.out.println(btn.getTag());
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.i("ToDo", "delete Row");
- long id = (Long) v.getTag();
- ob.DeleteRow( id); //moment control reaches this line process terminates
- Log.i("ToDo", "delete after");
- notifyDataSetChanged();
- Log.i("ToDo", "delete ");
- }
- });
- v.setLongClickable(true);
- return v;
- }
- }
- private void fillData() {
- Cursor c = mDbHelper.fetchAll();
- startManagingCursor(c);
- String[] from = new String[] { ToDoDBAdapter.KEY_TITLE,
- ToDoDBAdapter.KEY_CREATED_ON };
- int[] to = new int[] {R.id.Text1, R.id.Text2 };
- // to display list and time
- Log.i("ToDo", "Created custom adapter");
- this.lv = getListView();
- this.todo = new customAdapter(this,R.layout.simple, c, from,to);
- lv. setAdapter(todo);
- }
Advertisement
Add Comment
Please, Sign In to add comment