0

I want to display first 10 sms when activity open then after scrolling up display upper sms in listview As like following link i can display list by scrolling down and load items on onscroll

dynamic listview adding "Load more items" at the end of scroll

But i want to load sms at top so i am creating one function to display first 10 sms but after onscroll how can i load other sms...

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());


}

This have to work like whats up sms "LOAD more sms"...

Community
  • 1
  • 1
user2436235
  • 53
  • 1
  • 8
  • What happens if the screen can not physically display the first 10, but let's say, the first 8 (if this is a small screen) ? – g00dy Jul 22 '13 at 08:47
  • no. thats not a problem. by this function 1st 10 sms are loading but i want to load other sms after upscrolling listview – user2436235 Jul 22 '13 at 09:17
  • Ok ,then while adding to the list, can you make all the sms messages to be with visibility "GONE" and if `onFling()` or `OnScroll()` is detected to show them all ? Or it's not possible? – g00dy Jul 22 '13 at 09:51
  • when i click on read button for read conversation of person, its gets much time to load all conversation so i want to load first 10 then onscroll up load conversation – user2436235 Jul 22 '13 at 09:57
  • You can instead of this, load them dynamically one by one, in an AsyncTask, that way you can see them all appearing one after another and when you start reading the fist ones available, the list is going to be filled to the bottom. I think this is a better approach. – g00dy Jul 22 '13 at 10:58
  • yes this coding is done already but i want to do upscrolling loading in listview – user2436235 Jul 22 '13 at 11:02
  • Something like that, or I'm in error: http://stackoverflow.com/questions/12583419/android-listview-automatically-load-more-data-when-scroll-to-the-bottom – g00dy Jul 22 '13 at 11:14
  • this load data at the end of the list but i want to load data above 1st item of list ... – user2436235 Jul 22 '13 at 11:29

0 Answers0