Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:22:41+00:00 2026-06-09T20:22:41+00:00

I want to order all my db entries using ORDER BY in my db

  • 0

I want to order all my db entries using “ORDER BY” in my db table.
I don’t know what i’m doing wrong, but it doesn’t work.
Here my code:

class NoteHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "note.db";
private static final int SCHEMA_VERSION = 1;


public NoteHelper(Context context){
    super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db){
    db.execSQL("CREATE TABLE Notes (_id INTEGER PRIMARY KEY AUTOINCREMENT, note TEXT);");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
    //no-op, since will not be called until 2nd schema
    //version exists
}

public void insert(String note) {

    ContentValues cv = new ContentValues();
    cv.put("note", note);
    //you must pass it at lease one name of a colum
    getWritableDatabase().insert("Notes", "note", cv);
}

public void update(String id, String note){
    ContentValues cv = new ContentValues();
    String[] args = {id};

    cv.put("note", note);
    getWritableDatabase().update("Notes", cv, "_id=?", args);
}

public void delete(String id){
    getWritableDatabase().delete("Notes", "_id=?", new String[] {id});
}

public Cursor getAll(){
    return (getReadableDatabase().rawQuery("SELECT _id, note FROM Notes",  null));
}


public Cursor getAllSorted(){
    return (getReadableDatabase().rawQuery("SELECT note  FROM Notes  ORDER BY note  COLLATE NOCASE", null));

}

public String getNote(Cursor c){
    return(c.getString(1));
}

public Cursor getById(String id) {
    String[] args = {id};

    return(getReadableDatabase().rawQuery("SELECT _id, note FROM Notes WHERE _id=?", args));
}

 }

If someone knows where is the problem help me, thanks.

Ok here is the main code:

NoteAdapter adapter = null;
NoteHelper helper = null;
Cursor dataset_cursor = null;
EditText editNote = null;
//this is how track which note we are working on
String noteId = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    try{


    setContentView(R.layout.history);

    ListView list = (ListView)findViewById(R.id.list);
    editNote = (EditText)findViewById(R.id.myEditText);


    helper = new NoteHelper(this);
    dataset_cursor = helper.getAll();
    startManagingCursor(dataset_cursor);
    adapter = new NoteAdapter(dataset_cursor);
    list.setAdapter(adapter);
class NoteAdapter extends CursorAdapter {
    NoteAdapter(Cursor c){
        super(Ztutorial11.this, c);


    }




    public void bindView(View row, Context ctxt, Cursor c) {
        NoteHolder holder = (NoteHolder)row.getTag();
        holder.populateFrom(c, helper);
    }

    public View newView(Context ctxt, Cursor c, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.row, parent, false);
        NoteHolder holder = new NoteHolder(row);

        row.setTag(holder);
        return (row);
    }
}

static class NoteHolder {
    private TextView noteText = null;

    NoteHolder(View row){
        noteText = (TextView)row.findViewById(R.id.note);


    }

    void populateFrom(Cursor c, NoteHelper helper) {
        noteText.setText(helper.getNote(c));
    }
}



   public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater awesome = getMenuInflater();
awesome.inflate(R.menu.menu_expresions, menu);
return true;

   }
   public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.Az:

    //something to do
    helper.getAllSorted();
    //update the view
    dataset_cursor.requery();
    return true;
case R.id.Za:

    //something to do

    return true;
case R.id.deleteall:

    //something to do
    helper.deleteAll();
    dataset_cursor.requery();
    return true;
case R.id.undo:

    //something to do

    return true;

}

return false;
 }



 };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:22:43+00:00Added an answer on June 9, 2026 at 8:22 pm

    Try it that way:

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.Az:
                dataset_cursor = helper.getAllSorted();
                adapter.changeCursor(dataset_cursor);
                return true;
            case R.id.Za:
                // something to do
                return true;
            case R.id.deleteall:
                // something to do
                helper.deleteAll();
                dataset_cursor.requery();
                adapter.notifyDataSetChanged();
                return true;
            case R.id.undo:
                // something to do
                return true;
        }
        return false;
    }
    

    first you assign the new sorted result to dataset_cursor then tell the adapter, that the cursor has changed. The deleteall case will probably need the adapter.notifyDataSetChanged(); line I added there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table: ID name c_counts f_counts and I want to order all
My query is essentially the following: entries=Entry.all().order(-votes).order(-date).filter(votes >, VOTE_FILTER).fetch(PAGE_SIZE+1, page* PAGE_SIZE) I want to
I want to use all the photos in a Flickr set and in order
In order to localize strings used within my javascript, I want scan all my
I want to order by id asc, date asc, but in the case where
I want to order by Time,but seems no way to do that ? mysql>
I want to order values from database query by date but I want also
I have a time log table where all entries are entered with a time
I want to list (a sorted list) all my entries from an attribute called
I want to order grades that are a string in the following order. K,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.