Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with onListItemClick (mNotesCursor)
    primarykey
    data
    text
    <p>i am using the developer.android Notepad tutorial (<a href="http://developer.android.com/training/notepad/notepad-ex2.html" rel="nofollow">http://developer.android.com/training/notepad/notepad-ex2.html</a>) to create a Noteapp, but i have problems with the onItemClick and i cant figure out, where the problem lies.</p> <p>My Code</p> <pre><code>public class MainActivity extends ListActivity { private static final int ACTIVITY_CREATE=0; private static final int ACTIVITY_EDIT=1; public static final int INSERT_ID = Menu.FIRST; private static final int DELETE_ID = Menu.FIRST + 1; private int mNoteNumber = 1; private NotesDbAdapter mDbHelper; public static String notesstring; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDbHelper = new NotesDbAdapter(this); mDbHelper.open(); fillData(); registerForContextMenu(getListView()); ImageButton b = (ImageButton) findViewById(R.id.add); b.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { //Intent i = new Intent(MainActivity.this, NoteScreen.class); //startActivity(i); createNote(); } }); } private void fillData() { Cursor c = mDbHelper.fetchAllNotes(); startManagingCursor(c); String[] from = new String[] { NotesDbAdapter.KEY_TITLE }; int[] to = new int[] { R.id.text1 }; SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); setListAdapter(notes); } @Override public boolean onCreateOptionsMenu(Menu menu) { boolean result = super.onCreateOptionsMenu(menu); menu.add(0, INSERT_ID, 0, R.string.menu_insert); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.mainactivitymenu, menu); return result; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId() ) { case INSERT_ID: createNote(); return true; } switch (item.getItemId()) { case R.id.action_settings: Intent i = new Intent(MainActivity.this, Settings.class); startActivity(i); return true; /*case R.id.action_new: Intent e = new Intent(MainActivity.this, NoteScreen.class); startActivity(e); return true; */ default: return super.onOptionsItemSelected(item); } } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.add(0, DELETE_ID, 0, R.string.menu_delete); } @Override public boolean onContextItemSelected(MenuItem item) { switch(item.getItemId()) { case DELETE_ID: AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); mDbHelper.deleteNote(info.id); fillData(); return true; } return super.onContextItemSelected(item); } private void createNote() { Intent i = new Intent (this, NoteScreen.class); startActivityForResult(i, ACTIVITY_CREATE); /*String noteName = "Note " + mNoteNumber++; mDbHelper.createNote(noteName, ""); fillData();*/ } </code></pre> <p>And this is the part where the Errors are:</p> <pre><code>@Override protected void onListItemClick(ListView list, View v, int position, long id) { super.onListItemClick(list, v, position, id); Cursor c = mNotesCurser; c.moveToPosition(position); Intent i = new Intent(this, NoteScreen.class); i.putExtra(NotesDbAdapter.KEY_ROWID, id); i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString( c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE))); i.putExtra(NotesDbAdapter.KEY_BODY, c.getString( c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY))); startActivityForResult(i, ACTIVITY_EDIT); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); Bundle extras = intent.getExtras(); switch(requestCode) { case ACTIVITY_CREATE: String title = extras.getString(NotesDbAdapter.KEY_TITLE); String body = extras.getString(NotesDbAdapter.KEY_BODY); mDbHelper.createNote(title, body); fillData(); break; case ACTIVITY_EDIT: Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID); if (rowId != null) { String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE); String editBody = extras.getString(NotesDbAdapter.KEY_BODY); mDbHelper.updateNote(rowId, editTitle, editBody); } fillData(); break; } } </code></pre> <p>}</p> <p>mNotesCurser cannot be resolved to a variable</p> <p>Any idea how to fix this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload