SearchResult.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.usai.apex;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import org.json.JSONException;
  7. import org.json.JSONObject;
  8. import android.util.Log;
  9. public class SearchResult implements Serializable
  10. {
  11. /**
  12. *
  13. */
  14. private static final long serialVersionUID = 8847830656864696392L;
  15. int total_count = -1;
  16. // int direction = 1;
  17. int offset = 0;
  18. // int count = 0;
  19. ArrayList<HashMap<String, String>> records = new ArrayList<HashMap<String, String>>();
  20. public int get_recordscount() {
  21. return records.size();
  22. }
  23. public HashMap<String, String> get_record(int i) {
  24. return records.get(i);
  25. }
  26. public void add_records(String jsonstr) {
  27. try {
  28. records.clear();
  29. JSONObject objrecords = new JSONObject(jsonstr);
  30. for (int i = 0; i < objrecords.length(); i++) {
  31. // offset++;
  32. JSONObject rec = objrecords.getJSONObject("record" + i);
  33. Iterator<?> it = rec.keys();
  34. HashMap<String, String> record = new HashMap<String, String>();
  35. while (it.hasNext()) // loop for each function
  36. {
  37. String field_name = (String) it.next();
  38. String val = rec.getString(field_name)
  39. .replace("\n", "");
  40. record.put(field_name, val);
  41. }
  42. records.add(record);
  43. }
  44. } catch (JSONException e) {
  45. // TODO Auto-generated catch block
  46. e.printStackTrace();
  47. }
  48. String TAG = "init_fields@ResultActivity.SearchResult";
  49. Log.d(TAG, jsonstr);
  50. }
  51. public int get_totalcount() {
  52. return total_count;
  53. }
  54. public void put_totalcount(int c) {
  55. total_count = c;
  56. }
  57. public int get_offset() {
  58. return offset;
  59. }
  60. public void set_offset(int i) {
  61. offset = i;
  62. }
  63. }