title: how to run a code which is inside a Adapter every second in android
body: <p>Code</p>
  
  <pre><code> @Override
  public void onBindViewHolder(final MessageViewHolder holder, int position) {
  
      String current_user_id = mAuth.getInstance().getCurrentUser().getUid();
  
      Messages messages = mMessagesList.get(position);
      String from_user = messages.getFrom();
  
      if (from_user != null &amp;&amp; from_user.equals(current_user_id)) {
          holder.messageText.setTextColor(Color.BLACK);
  
  
          RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.messageText.getLayoutParams();
          params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
          holder.messageText.setLayoutParams(params);
  
          final Handler handler = new Handler();
          final int delay = 1000; //milliseconds
          final long Seen = messages.isSeen();
  
          handler.postDelayed(new Runnable(){
              public void run(){
  
                  if (Seen==1){
                      holder.messageText.setBackgroundResource(R.drawable.text_background2);
                  }else{
                      holder.messageText.setBackgroundResource(R.drawable.text_background1);
                  }
  
  
              }
          }, delay);
  
      }else {
              holder.messageText.setBackgroundResource(R.drawable.text_background2);
              holder.messageText.setTextColor(Color.BLACK);
  
          RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.messageText.getLayoutParams();
          params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
          holder.messageText.setLayoutParams(params);
          }
  
          holder.messageText.setText(messages.getMessage());
      }
  </code></pre>
  
  <p>Currently im trying to achieve the same like this... but just doesn't seem to happen... i get the desired result only after i refresh the activity... i want the code which is inside the runnable to execute every one second... is my approach correct? please help... thanks in advance</p>
  
  <p>Tried Solution </p>
  
  <pre><code>messageList = (RecyclerView) findViewById(R.id.message_list);
      linearLayoutManager = new LinearLayoutManager(getApplicationContext());
      mAdapter = new AdapterMessages(messagesList);
  
      messageList.setHasFixedSize(true);
      messageList.setLayoutManager(linearLayoutManager);
      messageList.setAdapter(mAdapter);
  
      final Handler handlerr = new Handler();
      int delay = 1000; //milliseconds
      final int finalDelay1 = delay;
      handlerr.postDelayed(new Runnable() {
          public void run() {
              mAdapter.notifyDataSetChanged();
              handlerr.postDelayed(this, finalDelay1);
          }
      }, delay);
  </code></pre>