@Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Cursor note = extObjDB.fetchNote(id);
    startManagingCursor(note);
    ObjSource s;
    int resource_id = note.getInt(note.getColumnIndexOrThrow(ExternObjDB.KEY_RESRC_ID));
    if (resource_id == -1) {
      // obj from sdcard
      String path = note.getString(note.getColumnIndexOrThrow(ExternObjDB.KEY_PATH));
      s = new ObjFromSDcard(path);
    } else {
      // obj from resource
      s = new ObjFromResource(resource_id);
    }
    s.Title = note.getString(note.getColumnIndexOrThrow(ExternObjDB.KEY_TITLE));
    s.Info = note.getString(note.getColumnIndexOrThrow(ExternObjDB.KEY_INFO));
    s.ID = note.getInt(note.getColumnIndexOrThrow(ExternObjDB.KEY_ROWID));
    Bundle bundle = new Bundle();

    bundle.putSerializable(ObjSource.TITLE, s);

    Intent mIntent = new Intent();
    mIntent.putExtras(bundle);
    setResult(RESULT_OK, mIntent);
    finish();
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.knots_list);
    extObjDB = new ExternObjDB(this);
    extObjDB.open();

    updateList();

    registerForContextMenu(getListView());
  }
  private void updateList() {
    Cursor notesCursor = extObjDB.fetchAllNotes();
    startManagingCursor(notesCursor);

    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[] {ExternObjDB.KEY_TITLE};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[] {R.id.text1};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes =
        new SimpleCursorAdapter(this, R.layout.knot_row, notesCursor, from, to);
    setListAdapter(notes);
  }
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   long id = info.id;
   switch (item.getItemId()) {
     case MENU_DELETE_NOTE:
       extObjDB.deleteNote(id);
       updateList();
       return true;
     case MENU_EDIT_NOTE:
       startEditNote(id);
       return true;
     default:
       return super.onContextItemSelected(item);
   }
 }
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
      case R.id.load_xml:
        FileDialog.StartFileDialog(this, ACT_LOAD_XML);
        // TODO
        return true;
      case R.id.add_obj:
        Intent i = new Intent(this, NoteEdit.class);
        // create and edit is the same, depends on parameters

        startActivityForResult(i, MENU_EDIT_NOTE);
        return true;
      case R.id.default_knots:
        extObjDB.AddDefaultKnots();
        updateList();
      case R.id.help_load:
        // TODO fill help
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
 @Override
 protected void onDestroy() {
   extObjDB.close();
   super.onDestroy();
 }
 public void addSDcardObj(String title, String path, String info) {
   extObjDB.createNote(title, path, info);
 }