ashu2121

get value from sqllit to list

Jan 27th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public static String user_name;
  2. public static String user_level;
  3.  
  4. public void user_id(){
  5. SQLiteDatabase db = this.getWritableDatabase();
  6. Cursor crs = db.rawQuery("SELECT * FROM android_api", null);
  7. List<String> array = new ArrayList<String>();
  8.  
  9. while(crs.moveToNext()){
  10. user_name=crs.getString(crs.getColumnIndex("name"));
  11. user_level = crs.getString(crs.getColumnIndex("level"));
  12. // adding data to list
  13. // use Hashmap as gobal variables so you can print in activity
  14. HashMap<Integer,String> hm=new HashMap<Integer,String>();
  15.  
  16. hm.put(user_name,user_level);
  17.  
  18. }
  19. }
  20.  
  21. -------------------
  22. print values it as
  23. for(Map.Entry m:hm.entrySet()){
  24. System.out.println(m.getKey()+" "+m.getValue());
  25. }
Add Comment
Please, Sign In to add comment