开发者

How to add next/back buttons to Notepad 3 on android?

开发者 https://www.devze.com 2023-02-20 16:23 出处:网络
I am trying to add next/back buttons on NoteEdit activity (Notepad Exercise 3 code). I\'ve created options menu and added two buttons there. In onOptionsItemSelected I\'ve written the following:

I am trying to add next/back buttons on NoteEdit activity (Notepad Exercise 3 code). I've created options menu and added two buttons there. In onOptionsItemSelected I've written the following:

case R.id.movie_menu_previous:
        Intent i = new Intent(this, MovieView.class);
        i.putExtra(MoviesDbAdapter.KEY_ROWID, mRowId+1);
        startActivity(i);
        return true;
case R.id.movie_menu_next:
        Intent i = new Intent(this, MovieView.class);
        i.putExtra(MoviesDbAdapter.KEY_ROWID, mRowId+1);
        startActivity(i);
    return true;

But the problem is that number of rows is limited. So, if user presses Next on the last row, I am开发者_Go百科 getting FC. How can I know that this is first row? last row? (I've modified the initial code and now in the database I have many records, but not all of them are shown in ListView) And, will not it be better to change logic of populateFields function and call it instead of creation new activity?


I've overridden populatefields function and added there the following:

mRowId = mDbHelper.getNextRecord(1, mRowId);

And here is the code of getNextRecord function:

public long getNextRecord(int next, long rowId) {
    long nextRowId = 0;
    Cursor mCursor = mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID,KEY_TITLE}, KEY_TITLE + "!=\"\"", null, null, null, null);
    if (mCursor.moveToFirst()) {
        do {
            if (mCursor.getLong(mCursor.getColumnIndexOrThrow(KEY_ROWID)) == rowId) {
                if (!mCursor.move(next)) {
                    // first (-1) or last position
                    if (mCursor.getPosition() == -1) {
                        mCursor.moveToLast();
                    } else {
                        mCursor.moveToFirst();
                    }
                }
                nextRowId = mCursor.getLong(mCursor.getColumnIndexOrThrow(KEY_ROWID));
                break;
            }
        } while (mCursor.moveToNext());
    }
        mCursor.close();
    return nextRowId;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号