I have a small problem.
My app has a database which stores lazy loaded images and Json values.
I have managed to store the values into my database,however i can’t seem to store them as
I want,they are stored into the database as
.
How can I make the entries to all start at the beginning of the database.
Bellow is my code.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
placeData = new DBHelper(this);
try {
Images("1","http://media.rightmove.co.uk/31k/30471/29462938
/30471_FLE100159_IMG_00_0002_max_200x138.jpg");
Images("2","http://media.rightmove.co.uk/3k/2265/35402969
/2265_9897_IMG_00_0000_max_200x138.jpg");
Images("3","http://media.rightmove.co.uk/75k/74944/18863829
/74944_OSI1000044_IMG_00_0000_max_200x138.jpg");
} catch (Exception e) {
}
try {
JSONArray properties = null;
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
properties = json.getJSONArray(TAG_PROPERTY);
// looping through All Contacts
for (int i = 0; i < properties.length(); i++) {
JSONObject c = properties.getJSONObject(i);
String identifier = c.getString(TAG_IDENTIFIER);
String price = c.getString(TAG_PRICE);
String bedrooms = c.getString(TAG_BEDROOMS);
String address = c.getString(TAG_ADDRESS);
String propertyType =
c.getString(TAG_PROPERTYTYPE);
id = id;
if (properties != null) {
// insert to database
insertData(id,identifier, price, bedrooms,
address,propertyType);
}
}
} catch (Exception e) {
}
} catch (Exception e) {
}
}
private void insertData(String id,String identifier, String price,
String bedrooms,String address, String propertyType) {
// TODO Auto-generated method stub
SQLiteDatabase db = placeData.getWritableDatabase();
ContentValues v = new ContentValues();
v.put(DBHelper.C_ID, id);
v.put(DBHelper.C_IDENTIFIER, identifier);
v.put(DBHelper.C_PRICE, price);
v.put(DBHelper.C_BEDROOMS, bedrooms);
v.put(DBHelper.C_ADDRESS, address);
v.put(DBHelper.C_PROPERTYTYPE, propertyType);
db.insert(DBHelper.TABLE, null, v);
db.close();
}
private void Images(String id, String url) throws ClientProtocolException,
IOException {
// TODO Auto-generated method stub
DefaultHttpClient mHttpClient = new DefaultHttpClient();
HttpGet mHttpGet = new HttpGet(url);
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = mHttpResponse.getEntity();
if (entity != null) {
// insert to database
insert(id, EntityUtils.toByteArray(entity));
}
}
}
private void insert(String id, byte[] image) {
// TODO Auto-generated method stub
SQLiteDatabase db = placeData.getWritableDatabase();
ContentValues v = new ContentValues();
v.put(DBHelper.C_ID, id);
v.put(DBHelper.C_PHOTOS, image);
db.insert(DBHelper.TABLE, null, v);
db.close();
}
Any help or advice will be appreciated.Thanks
you don’t ‘store’ them in any order – you ‘retrieve’ them in whichever order you want.
or similar