It's quite a common question but still I'm unable to implement it. In my application, I'm fetching Inbox messages
and displaying them in ListView
. Code is working fine but onStartup it loads all messages from inbox to listview. But I want when application starts it loads only first 15 message
after that a button having label LoadMore
will show and when clicking button next 15 messages will add to listview. Here's my code snippet:
listViewSMS=(ListView)findViewById(R.id.lvSMS);
listViewSMS.setAdapter(smsListAdapter);
getInboxSms();
smsListAdapter = new SMSListAdapter(this,populateSMSList());
listViewSMS.setAdapter(smsListAdapter);
public void getInboxSms() {
ContentResolver cr = getContentResolver();
c = cr.query(Uri.parse("content://sms/inbox"), null, null, null, null);
totalSMS = c.getCount();
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
Log.d("SMSss", "Contact number : "+ c.getString(c.getColumnIndexOrThrow("address"))+ "\n"
+ "msg : " + c.getColumnIndexOrThrow("body")
+ "\n"+ "Person : "
+ getContactName(c.getString(c.getColumnIndexOrThrow("address"))));
c.moveToNext();
}
}
}
private List<SMSListModel> populateSMSList()
{
if(c.getCount()>0)
{
for(int i=0;i<c.getCount();i++)
{
if(c.moveToPosition(i))
{
if(getContactName(c.getString(c.getColumnIndex("address"))) == null )
{
list.add(new SMSListModel(c.getString(c.getColumnIndex("address")),c.getString(c.getColumnIndex("body"))));
}
}
}
}
return list;
}
Any help will be appreciated. Thanks