我希望在活动打开后显示前10个短信然后在列表视图中向上滚动显示上部短信 如下面的链接我可以通过向下滚动并在onscroll上加载项目来显示列表
dynamic listview adding "Load more items" at the end of scroll
但是我想在顶部加载短信,所以我创建一个函数来显示前10个短信但是在onscroll之后如何加载其他短信......
public void readConversation() {
StringBuilder smsBuilder = new StringBuilder();
for(int i=0;i < ((IdSMSCount.size()>NO_OF_SMS_TO_LOAD )? NO_OF_SMS_TO_LOAD:IdSMSCount.size()) ; i++){
cur = getContentResolver().query(Uri.parse(SMS_URI_ALL), null,"thread_id = '" + strthread + "'"+" AND "+" _id ="+IdSMSCount.get(i), null, "date DESC");
startManagingCursor(cur);
while (cur.moveToNext() ){
String smsAdress = cur.getString(
cur.getColumnIndexOrThrow("address")).toString();
String smstype = cur.getString(
cur.getColumnIndexOrThrow("type")).toString();
if(smsAdress !=null){
String smsbody = cur.getString(
cur.getColumnIndexOrThrow("body")).toString();
String smsid = cur.getString(
cur.getColumnIndexOrThrow("_id")).toString();
smsthreadid = cur.getString(
cur.getColumnIndexOrThrow("thread_id")).toString();
String smsdate = cur.getString(
cur.getColumnIndexOrThrow("date")).toString();
String smsStatus = cur.getString(
cur.getColumnIndexOrThrow("status")).toString();
String smsReadUnread = cur.getString(
cur.getColumnIndexOrThrow("read")).toString();
String contactnamelist = getContactDisplayNameByNumber(smsAdress);
Log.d("smsReadUnread without check", smsReadUnread);
Log.d("sms id", str_id);
if(smsReadUnread.equals("0"))
{
smsReadUnread = "1";
ContentValues values = new ContentValues();
values.put("read", true);
Log.d("sms id", str_id);
Log.d("sms read and unread status", smsReadUnread);
getContentResolver().update(Uri.parse("content://sms/"),values, "_id="+str_id, null);
Log.d("smsReadUnread change", smsReadUnread);
}
int index = listconvo.getFirstVisiblePosition();
View v = listconvo.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
listconvo.setSelectionFromTop(index, top);
if(!smstype.equals("3"))
{
IdSMS.add(top,smsid);
SMSDate.add(top,smsdate);
MessageList.add(top,smsbody);
NumberList.add(top,contactnamelist);
SMSType.add(top,smstype);
SMSStatus.add(top,smsStatus);
SMSRead.add(top,"1");
Log.d("Conversation id", smsid);
Log.d("Conversation Address", smsAdress);
Log.d("Conversation body", smsbody);
Log.d("Conversation date", smsdate);
Log.d("Conversation type", smstype);
Log.d("Conversation status", smsStatus);
Log.d("Conversation Read(1)-Unread(0)", smsReadUnread);
Log.d("Conversation thread_id", smsthreadid);
}
}
counter ++;
Log.e("counter ", "Counter Value "+counter);
Log.d("IdSMSCount??",""+ IdSMSCount.size());
}
cur.close();
}
Log.d("IDSMS_Conversation??",""+ IdSMSCount.size());
adaptorConversation = new adaptorConversations(getApplicationContext(), IdSMS, SMSDate, MessageList, NumberList, SMSType, SMSStatus, SMSRead);
listconvo.setAdapter(adaptorConversation);
adaptorConversation.notifyDataSetChanged();
listconvo.setOnScrollListener(new listScrollConvo());
}
这必须像短信一样工作“加载更多短信”......