lundi 16 février 2015

Want some data from sqlite in android

I am currently working on rss feed and i am getting data from feed so basically i want to store the data in sqlite database in android. I am able to insert the data but the problem is that after inserting the all data i am able to view the data in list view. So if there is 1 lakh data then after inserting the 1 lakh data in database then i am able to show data. So i want to know is it possible to see the some amount of data from database in listview and after some time some other. Here is my code.



List<RssItem> items = (List<RssItem>) resultData
.getSerializable(RssService.ITEMS);
if (items != null) {
RssAdapter adapter = new RssAdapter(getActivity(), items);
for (int i = 0; i < items.size(); i++) {

String dc_date = items.get(i).getDc_date();
String description = items.get(i).getDescription();
Log.e("Tag", "Description:==" + description);
String dec1 ;
if (description.contains("</p>")) {
String dec = description.substring(description.indexOf("</p>"),
description.lastIndexOf("."));
dec1 = dec.substring(description.indexOf(" "));
} else {
dec1 = description;
// progressBar.setVisibility(View.GONE);
}
// String dec1 = dec.substring(description.indexOf(" "));

String guid = items.get(i).getGuid();
String pubdate = items.get(i).getPubDate();
String title = items.get(i).getTitle();
String mFinalURL;
if (description.contains("width=")) {
String url = description.substring(
description.indexOf("img src"),
description.lastIndexOf("width"));
mFinalURL = url.substring(url.indexOf("http"),
url.lastIndexOf('"'));
} else {
mFinalURL = "http://ift.tt/1F32v7X";
}

DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(mFinalURL);
HttpResponse response;
try {
response = client.execute(request);
HttpEntity entity = response.getEntity();
int imageLength = (int) (entity.getContentLength());
InputStream is = entity.getContent();
BufferedInputStream bufin = new BufferedInputStream(is,
128);
ByteArrayBuffer barrbuf = new ByteArrayBuffer(128);
int current = 0;
while ((current = bufin.read()) != -1) {
barrbuf.append((byte) current);

}

mDbHelper.openDataBase();
String count = "SELECT count(*) FROM Rss_Feed_Updated";
Cursor mcursor = mDbHelper.myDataBase.rawQuery(count,
null);

if (isInternet()) {
if (mcursor != null) {
mDbHelper.Insertrss(mDbHelper.myDataBase,
title, dec1, pubdate, guid, dc_date,
barrbuf.toByteArray());
} else {
mDbHelper.Updaterss(mDbHelper.myDataBase,
title, dec1, pubdate, guid, dc_date,
barrbuf.toByteArray());
}

} else {

Log.v("TRUE", "PLEASE CHECK YOUR INTERNET");
AlertDialog.Builder builder1 = new AlertDialog.Builder(
getActivity());
builder1.setMessage("PLEASE CHECK YOUR INTERNET");
builder1.setCancelable(true);
builder1.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();

}

} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

listView.setAdapter(adapter);
} else {
Toast.makeText(getActivity(),
"An error occured while downloading the rss feed.",
Toast.LENGTH_LONG).show();
}

Aucun commentaire:

Enregistrer un commentaire