Esempio n. 1
0
  public static final ArrayList<CityBean> getCityList(Context mContext) {
    CityListDBProvider.isFirstGet = true;
    ArrayList<CityBean> cityList = new ArrayList<CityBean>(CAPACITY_SIZE);
    Uri uri = UriHelper.getUri(CityListDBProvider.CITY_TABLE);

    Cursor cursor =
        mContext
            .getContentResolver()
            .query(uri, SUMMARY_PROJECTION, QUERY_CITY_LIST_BY_ALL, null, SORT_ORDER_BY_PINYIN);
    if (cursor == null || !cursor.moveToFirst()) {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      return null;
    }
    do {
      CityBean city = new CityBean();
      city.setId(cursor.getInt(ID_INDEX));
      city.setName(cursor.getString(NAME_INDEX));
      city.setPinyin(cursor.getString(PINYIN_INDEX));

      cityList.add(city);
    } while (cursor.moveToNext());

    cursor.close();
    cursor = null;

    return cityList;
  }
Esempio n. 2
0
  public static final ArrayList<CityBean> getSearchCityList(Context mContext, String searchStr) {
    //		CityListDBProvider.isFirstGet = false;
    ArrayList<CityBean> cityList = new ArrayList<CityBean>();
    Uri uri = UriHelper.getUri(CityListDBProvider.CITY_TABLE);

    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                uri,
                SUMMARY_PROJECTION,
                NAME + " like '%" + searchStr + "%' or " + PINYIN + " like '%" + searchStr + "%'",
                null,
                SORT_ORDER_BY_PINYIN);
    //		Cursor cursor = mContext.getContentResolver()
    //				.query(uri, SUMMARY_PROJECTION, QUERY_CITY_LIST_BY_SEARCH,
    //						new String []{ searchStr ,searchStr }, SORT_ORDER);
    if (cursor == null || !cursor.moveToFirst()) {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      return null;
    }
    do {
      CityBean city = new CityBean();
      city.setId(cursor.getInt(ID_INDEX));
      city.setName(cursor.getString(NAME_INDEX));
      city.setPinyin(cursor.getString(PINYIN_INDEX));

      cityList.add(city);
    } while (cursor.moveToNext());

    cursor.close();
    cursor = null;

    return cityList;
  }