title: Message view from both side in android
body: <p>I'm working on a chatting application. All I did is i can get api response successfully and can show them serially like this</p>
  
  <p><a href="https://i.stack.imgur.com/Q318c.png" rel="nofollow noreferrer">This is id of sender and reciver</a></p>
  
  <p><a href="https://i.stack.imgur.com/glNG1.png" rel="nofollow noreferrer">This is the messages</a></p>
  
  <p>For doing this I created an adapter which code is something like this.</p>
  
  <pre><code>public class Single_chat_adapter extends RecyclerView.Adapter&lt;Single_chat_adapter.Single_chat_adapterViewHolder&gt;{
  
  
  private List&lt;Datum2&gt; data;
  private int rowLayout;
  private Context context;
  
  public Single_chat_adapter(List&lt;Datum2&gt; data, int rowLayout, Context context) {
      this.data = data;
      this.rowLayout = rowLayout;
      this.context = context;
  }
  
  @Override
  public Single_chat_adapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card2, parent, false);
      return new Single_chat_adapterViewHolder(view);    }
  
  @Override
  public void onBindViewHolder(Single_chat_adapterViewHolder holder, int position) {
      holder.single_msg.setText(data.get(position).getMsg());
  }
  
  @Override
  public int getItemCount() {
      return data.size();
  }
  
  public class Single_chat_adapterViewHolder extends RecyclerView.ViewHolder {
  
      TextView single_msg;
  
      public Single_chat_adapterViewHolder(View itemView) {
          super(itemView);
          single_msg =itemView.findViewById(R.id.userNameTV);
      }
  }
  }
  </code></pre>
  
  <p>Here I use a single view which is <strong>card2.xml.</strong> But all I need to do is set senders message in the left side and receiver message in other side.
  What To do?</p>