title: How to add ImageView/TextView in a Android List view with custom adapter?
body: <p>I am creating a Android app , in which i have a list view with chat bubbles (speech bubbles ) i want to add image in those chat bubbles, if user insert a Image from options , My app look likes this --></p>
  
  <p><img src="https://i.stack.imgur.com/DN2Ew.jpg" alt="enter image description here"></p>
  
  <p>I want to insert this image in the app , when user insert it through the image button , I have customized the Adapter so far by myself , please take a look at my AwesomeAdapter class , and Main_activity </p>
  
  <p><strong>Main_Activity.java</strong></p>
  
  <pre><code>    @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          start();
          text = (EditText) this.findViewById(R.id.txtMessage);
          sndButton=(Button)findViewById(R.id.buttonchat3);
          //sndButton.setEnabled(false);
          messages = new ArrayList&lt;Message&gt;();
  
          adapter = new AwesomeAdapter(this, messages);
          setListAdapter(adapter);
  
      }
  
  
  
      public void sendMessage(View v)
      {   
          String newMessage = text.getText().toString().trim(); 
          if(newMessage.length() &gt; 0)
          {
              text.setText("");
              addNewMessage(new Message(newMessage, true));
              mConnection.sendTextMessage(newMessage);
  
          }
      }
  
      public void receiveImage(View v)
      {
          Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
          photoPickerIntent.setType("image/*");
          startActivityForResult(photoPickerIntent,RESULT_LOAD_IMAGE);    
  
      }
  
  void addNewMessage(Message m)
      {
          messages.add(m);
          adapter.notifyDataSetChanged();
          getListView().setSelection(messages.size()-1);
      }
  
      @SuppressWarnings("static-access")
      void addReceivedMessage(Message m)
      {
          messages.add(m);
          adapter.notifyDataSetChanged();
          getListView().setSelection(messages.size()-1);
          v=(Vibrator) getSystemService(this.VIBRATOR_SERVICE);
          v.vibrate(200);
      }
  </code></pre>
  
  <p><strong>AwesomeAdapter.java</strong>
  this is the Adapter class for the list view where i am showing this textbox and 9 patch image in background,</p>
  
  <p>public class AwesomeAdapter extends BaseAdapter{</p>
  
  <pre><code>  private static final int TYPE_ITEM = 0;
    private static final int TYPE_SEPARATOR = 1;
    private static final int TYPE_MAX_COUNT = TYPE_SEPARATOR + 1;
  
  private Context mContext;
  private ArrayList&lt;Message&gt; mMessages;
  
   //private TreeSet mSeparatorsSet = new TreeSet();
  
  public AwesomeAdapter(Context context, ArrayList&lt;Message&gt; messages) {
      super();
      this.mContext = context;
      this.mMessages = messages;
  }
  @Override
  public int getCount() {
      return mMessages.size();
  }
  @Override
  public Object getItem(int position) {
  
      return mMessages.get(position);
  }
  
   @Override
   public int getItemViewType(int position) {
       if(my code to get text content) //it will fetch the textview layout 
       {
       return TYPE_SEPARATOR; 
       }
       else //it will fetch the image view layout
       {
     return TYPE_ITEM;
       }
   }
  
   @Override
   public int getViewTypeCount() {
       return TYPE_MAX_COUNT;
   }
  
  
  
  @SuppressLint("ResourceAsColor")
  @SuppressWarnings("deprecation")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      Message message = (Message) this.getItem(position);
  
      ViewHolder holder; 
      int type = getItemViewType(position);
      if(convertView == null)
      {
          holder = new ViewHolder();
          switch (type) {
          case TYPE_ITEM:
          convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false);
          holder.message = (TextView) convertView.findViewById(R.id.message_text);
           break;
          case TYPE_SEPARATOR:
              convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row2, parent, false);
              holder.message = (TextView) convertView.findViewById(R.id.message2);
  
              break;
          }
          convertView.setTag(holder);
      }
      else
          holder = (ViewHolder) convertView.getTag();
  
      holder.message.setText(message.getMessage());
  
      LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
      //check if it is a status message then remove background, and change text color.
      if(message.isStatusMessage())
      {
          holder.message.setBackgroundDrawable(null);
          lp.gravity = Gravity.LEFT;
          holder.message.setTextColor(R.color.textFieldColor);
      }
      else
      {       
          //Check whether message is mine to show green background and align to right
          if(message.isMine())
          {
              holder.message.setBackgroundResource(R.drawable.speech_bubble_orange);
              lp.gravity = Gravity.LEFT;
          }
          //If not mine then it is from sender to show orange background and align to left
          else
          {
              holder.message.setBackgroundResource(R.drawable.speech_bubble_green);
              lp.gravity = Gravity.RIGHT;
          }
          holder.message.setLayoutParams(lp);
          holder.message.setTextColor(R.color.textColor); 
      }
      return convertView;
  }
  private static class ViewHolder
  {
      TextView message;
  }
  
  @Override
  public long getItemId(int position) {
      //Unimplemented, because we aren't using Sqlite.
      return 0;
  }
  
  }
  </code></pre>
  
  <p>I have made the sms_row1 and sms_row2 files , now how should i start the working of this another View , i am new to android tried a lot of changes , but it still does not work , please help and thanx in advance.</p>