title: Load Earlier Messages in listview like whats app
body: <p>When i Click load earlier messages the earlier messages get loaded from database but list view scrolls to the top which is not be done , the message should only loaded at the top of list view without its scroll.</p>
  
  <p>Here is my code for main Activity</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.private_group_chat);
  
      Intent i = getIntent();
      btnLoadMore = new Button(this);
      btnLoadMore.setText("Load Earlier Messages");
      lsvChat = (ListView) findViewById(R.id.lv_messsages);
      lsvChat.addHeaderView(btnLoadMore);
      chatModel = new ArrayList&lt;ChatModel&gt;();
      db = new Database3(getApplicationContext());
      chatModel = db.getSelectedIncidentDetails(getApplicationContext(),
              groupId, count);
      chatAdapter = new ChatAdapterGroup(getApplicationContext(), chatModel);
      lsvChat.setAdapter(chatAdapter);
      discoverModel = new ArrayList&lt;DiscoverModel&gt;();
      dm = new DiscoverModel();
  
  }
  </code></pre>
  
  <p>here is my base adapter......</p>
  
  <pre><code>public class ChatAdapterGroup extends BaseAdapter {
  
      private Context context;
      private LayoutInflater inflater;
      int count = 0;
      private ArrayList&lt;ChatModel&gt; list;
  
      public ChatAdapterGroup(Context context, ArrayList&lt;ChatModel&gt; list) {
          this.context = context;
          this.list = list;
  
          inflater = (LayoutInflater) context
                  .getSystemService(context.LAYOUT_INFLATER_SERVICE);
      }
  
      @Override
      public int getCount() {
          return list.size();
      }
  
      @Override
      public Object getItem(int position) {
          return list.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      private class ViewHolder {
          TextView txt_left;
          TextView txt_right;
          TextView tv_fromName;
          RelativeLayout rl_left;
          RelativeLayout rl_right;
      }
  
      @Override
      public View getView(final int position, View v, ViewGroup arg2) {
  
          final ViewHolder holder;
          if (v == null) {
  
              holder = new ViewHolder();
              v = inflater.inflate(R.layout.chat_adapter, null);
  
              holder.txt_left = (TextView) v.findViewById(R.id.txt_left);
  
              holder.txt_right = (TextView) v.findViewById(R.id.txt_right);
  
              holder.tv_fromName = (TextView) v.findViewById(R.id.tv_fromName);
  
              holder.rl_left = (RelativeLayout) v.findViewById(R.id.rl_left);
  
              holder.rl_right = (RelativeLayout) v.findViewById(R.id.rl_right);
  
              v.setTag(holder);
  
          } else {
              holder = (ViewHolder) v.getTag();
  
          }
  
          if (list.get(position) != null) {
  
              if (list.get(position).getGroup_cordinate()
                      .equalsIgnoreCase("left")) {
                  holder.txt_left.setText(""
                          + list.get(position).getGroup_messages_recive());
                  holder.tv_fromName.setText(""
                          + list.get(position).getFrom_name_recive());
                  holder.txt_left.setTextColor(Color.parseColor("#000000"));
                  holder.rl_right.setVisibility(View.GONE);
                  holder.rl_left.setVisibility(View.VISIBLE);
              } else {
                  holder.txt_right.setText(""
                          + list.get(position).getGroup_messages_recive());
                  holder.rl_left.setVisibility(View.GONE);
                  holder.rl_right.setVisibility(View.VISIBLE);
  
              }
  
          }
  
          v.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  // notifyDataSetChanged();
              }
          });
          return v;
      }
  
  }
  </code></pre>
  
  <p>and the xml coding for List view .............</p>
  
  <pre><code>&lt;ListView
          android:id="@+id/lv_messsages"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_above="@+id/ll_send"
          android:layout_below="@+id/rl_header"
          android:divider="@null"
          android:stackFromBottom="true"
          android:transcriptMode="alwaysScroll" /&gt;
  </code></pre>