lundi 26 octobre 2015

refresh listview with timer without scroling?

This is the timer to refresh the listview to check for any new entry in sqlite. and whenever timer goes over, it refreshes the listview again and again. In that case, I want that the timer should have no effect on the listview. It should add the new entry in at the end without scrolling it down again again.

Timer t = new Timer();
                    t.scheduleAtFixedRate(new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                public void run() {


                                    get_chat_data();

                                }
                            });
                        }
                    }, 500, 1000);

This is the function which is called in the timer

private void get_chat_data() {

      String fuid = getIntent().getExtras().getString("uid");
    HashMap<String, String> user = session.getUserDetails();
    String uid = user.get(SessionManager.KEY_UID);



            //  Fetching user details from sqlite
            db = new SQLiteHandler(getApplicationContext());
            /*
            *
            * sender chat
            *
            * */

            HashMap<String, String> user_info = db.CHAT_DATA_IN_LIST_VIEW(fuid, uid);

            String s_chat= user_info.get("s_chat");
            String mtime= user_info.get("mtime");
            String mdate= user_info.get("mdate");
            String spic= user_info.get("s_pic");


            String []  s_chat1 = s_chat.split(":");
            String []  mtime1 = mtime.split("=");
            String []  mdate1 = mdate.split(":");
            String []  spic1 = spic.split(":");


            /**
             *
             * reciver chat
             *
             * */

            HashMap<String, String> user_info1 = db.CHAT_DATA_IN_LIST_VIEW1(fuid, uid);
            String r_chat= user_info1.get("r_chat");
            String rpic= user_info1.get("r_pic");
            String friendid= user_info1.get("com_id");

            String []  r_chat1 = r_chat.split(":");
            String []  rpic1 = rpic.split(":");






            list.setAdapter(new Custom_Adapter_chat(this, s_chat1, r_chat1, spic1, rpic1, mtime1, mdate1));


        }

Aucun commentaire:

Enregistrer un commentaire