Ejemplo n.º 1
0
  private void fillData() {
    mCursor = mDbHelper.getAll();
    startManagingCursor(mCursor);

    String[] from_column = new String[] {DB.KEY_ITEM, DB.KEY_CREATED};
    int[] to_layout = new int[] {R.id.text1, R.id.text2};

    // Now create a simple cursor adapter
    //	    SimpleCursorAdapter adapter =
    //	                new SimpleCursorAdapter(this, R.layout.list_row,
    //	                		mCursor, from_column, to_layout);

    // Now create list with cursor
    ListCursorAdapter adapter = new ListCursorAdapter(this, mCursor);

    setListAdapter(adapter);

    getListView()
        .setOnItemClickListener(
            new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                //	    		Cursor c = ((SimpleCursorAdapter)getListView().getAdapter()).getCursor();
                //	    		c.moveToPosition(position);
                //	    		mDbHelper.delete(c.getLong(0));

                mDbHelper.delete(id);
                fillData();
              }
            });
  }
Ejemplo n.º 2
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    AdapterView.AdapterContextMenuInfo info;
    info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
      case R.id.action_delete:
        mDbHelper.delete(info.id);
        fillData();
        break;
    }
    return super.onContextItemSelected(item);
  }
Ejemplo n.º 3
0
  private void setAdapter() {
    mDbHelper = new DB(this);
    mDbHelper.open();

    //		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    //			    android.R.layout.simple_list_item_1,
    //			    records);
    //		setListAdapter(adapter);

    //		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    //				R.array.records,
    //				android.R.layout.simple_list_item_1);
    //		setListAdapter(adapter);

    //		setListAdapter(new ArrayAdapter<String>(this,
    //                android.R.layout.simple_list_item_1,
    //                records));

    fillData();
  }