0

我想在活动打开时显示前 10 条短信,然后在向上滚动后在列表视图中显示上部短信就像下面的链接一样,我可以通过向下滚动来显示列表并在 onscroll 上加载项目

动态列表视图在滚动结束时添加“加载更多项目”

但是我想在顶部加载短信,所以我正在创建一个函数来显示前 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());


}

这必须像什么短信“加载更多短信”一样工作......

4

0 回答 0