I am fetching data from server and don't know the number of records being fetched. I am saving the data in sqlite and displaying it using cursor. I want to display first 10 records initially in listview. On next button click next 10 records should be displayed in the same listview and so on. Please suggest me a way.
Code:
runOnUiThread(new Runnable() {
@Override
public void run() {
//stuff that updates ui
/**
* Updating parsed JSON data into ListView
* */
disp();
}
});
public void disp() {
try {
Cursor c;
String sql = "select * from CurrentAffairs LIMIT 10";
c = sdb.rawQuery(sql, null);
int rowCount=c.getCount();
Constants.i=rowCount;
if (c != null) {
// if (c.moveToNext()) {
while (c.moveToNext()) {
String message = c.getString(c.getColumnIndex("message"));
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key =>
// value
map.put(TAG_MESSAGE, message);
result.add(message);
}// while(c.moveToNext());
}
} catch (Exception e) {
// TODO: handle exception
Log.i("In Banking economics", "Error-" + e.toString());
e.printStackTrace();
}
//ListAdapter adapter = new SimpleAdapter(Banking_Economics.this, result,R.layout.list_item, new String[] { TAG_MESSAGE },new int[] { R.id.textView1 });
ListAdapter adapter=new ArrayAdapter<String>(this, R.layout.list_item,R.id.textView1, result);
setListAdapter(adapter);
// selecting single ListView item
lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String message = ((TextView) view.findViewById(R.id.textView1))
.getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), News.class);
in.putExtra(TAG_MESSAGE, message);
startActivity(in);
}
});
}
I have tried using separate arraylists for every 10 records but as the number of records are not known its not working. Also I don't have knowledge about pagination so can't use it. Any help appreciated
Note: The data from server gets updated daily and new records get added. I want to display these new records on first load of listview.