-2

I want to add alphabetical order to arraylist from db(whatever values). my code like this

ArrayList<ContentValues> array_main = new ArrayList<ContentValues>();
ContentValues values1 = new ContentValues();
values1.put(MyHelper.OVEN_ID, _id);
                        values1.put(MyHelper.USERNAME, user);
                        values1.put(MyHelper.DESCRIPTION, des);
                        values1.put(MyHelper.IMAGE, image);
                        values1.put(MyHelper.DATE, date);
                        values1.put(MyHelper.NAME, title);
                        values1.put(MyHelper.FOOD, food);
                        values1.put(MyHelper.RATING, rates);
                        values1.put(MyHelper.INGREDIENTS, ingre);
                        values1.put(MyHelper.DIRECTIONS, direct);

i can change only MyHelper.Name to alphabetical order in arraylist. and thanks for responsibility.

Nivas Devarapalli
  • 111
  • 1
  • 2
  • 10

1 Answers1

0

You could let your database do the sorting when you get the information from the database

....
Arraylist<objecttype> newList =new ArrayList<objecttype>();
String selTable = "select * from object order by object_name desc";
s.execute(selTable);
ResultSet rs = s.getResultSet();
while((rs!=null) && (rs.next()))
 {
    newList.Add(rs); //something like that
 }

Use Asc or Desc in your select statement, depending on how you want to sort.

Moelbeck
  • 591
  • 2
  • 7
  • 29