title: Android: Having trouble with newline in TextView inside BaseAdapter
body: <p>Basically I am inserting text along with new line character in mysql db like this:</p>
  
  <pre><code>$message = 'Hello World' . "\n";
  $message .= 'This is a test' . "\n";
  $message .= 'Thanks;
  </code></pre>
  
  <p>When saving message in db, I have tried setting value of new line as <code>\n</code>, <code>\\n</code>, <code>\\\n</code>, <code>\\\\n</code> and even <code>&lt;br&gt;</code> instead of <code>\n</code> then used <code>fromHtml</code> on android app but nothing working out.</p>
  
  <p>In db, I can see there is new line.</p>
  
  <p>On Android app I want to have new line character if any showed in TextView, I have tried various things but nothing is working, I've tried things like:</p>
  
  <pre><code>String message = m.getMessage().toString();
    message = message.replaceAll("\\n",
        System.getProperty("line.separator"));
  </code></pre>
  
  <p>Here instead of <code>"\\n"</code>, I have also tried <code>"\\\n"</code>, <code>"\n"</code> and even <code>"\\\\n"</code></p>
  
  <p>And:</p>
  
  <pre><code>Spanned html = Html.fromHtml(m.getMessage());
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>message.replaceAll("\n","&lt;br /&gt;");
  message.replaceAll("\r\n","&lt;br /&gt;");
  message.replaceAll("\r","&lt;br /&gt;");
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>android:singleLine="false"
  </code></pre>
  
  <p>With various things tried, in TextView I get text like these permutations:</p>
  
  <pre><code>Hello WorldThis is a testThanks
  
  Hello World\This is a test\Thanks
  
  Hello World\nThis is a test\nThanks
  </code></pre>
  
  <p>Here is my complete code:</p>
  
  <pre><code>public class MessageListAdapter extends BaseAdapter {
  
      private Context context;
      private List&lt;ListMessage&gt; messagesItems;
  
      public MessageListAdapter(Context context, List&lt;ListMessage&gt; navDrawerItems) {
          this.context = context;
          this.messagesItems = navDrawerItems;
      }
  
      @Override
      public int getCount() {
          return messagesItems.size();
      }
  
      @Override
      public Object getItem(int position) {
          return messagesItems.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @SuppressLint("InflateParams")
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          /**
           * The following list not implemented reusable list items as list items
           * are showing incorrect data Add the solution if you have one
           * */
  
          ListMessage m = messagesItems.get(position);
  
          LayoutInflater mInflater = (LayoutInflater) context
                  .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
  
          // Identifying the message owner
          if (messagesItems.get(position).isSelf()) {
              // message belongs to you, so load the right aligned layout
              convertView = mInflater.inflate(R.layout.list_item_message_right,
                      null);
          } else {
              // message belongs to other person, load the left aligned layout
              convertView = mInflater.inflate(R.layout.list_item_message_left,
                      null);
          }
  
          TextView lblFrom = (TextView) convertView
                  .findViewById(R.id.lblMsgFromListMessage);
          TextView lblTo = (TextView) convertView
                  .findViewById(R.id.lblMsgToListMessage);
  
          lblFrom.setText(m.getFromName());
  
          // Spanned html = Html.fromHtml(m.getMessage());
          // String message = html.toString();
  
          String message = m.getMessage().toString();
          message = message.replaceAll("\\n",
                  System.getProperty("line.separator"));
  
          try {
              lblTo.setText(message);
  
          } catch (Exception e) {
              lblTo.setText(message);
          }
  
          return convertView;
      }
  }
  </code></pre>
  
  <p>TextView in layout:</p>
  
  <pre><code>&lt;TextView
      android:id="@+id/lblMsgToListMessage"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="50dp"
      android:background="@drawable/chat_bg_msg_from"
      android:paddingBottom="@dimen/five_dp"
      android:paddingLeft="@dimen/ten_dp"
      android:paddingRight="@dimen/ten_dp"
      android:paddingTop="@dimen/five_dp"
      android:textColor="@color/chat_title_gray"
      android:textSize="@dimen/eighteen_sp" /&gt;
  </code></pre>
  
  <p>Is something wrong with <code>baseAdaptor</code>? Somewhere I saw <a href="http://android.jreactor.com/2012/07/17/simpleadapter-spanned-html-fromhtml/" rel="nofollow">this link</a>, it suggested <code>SimpleAdapter</code> has problem setting html but in my case this doesn't help either since I am using <code>BaseAdapter</code>.</p>
  
  <p>I will be really realy thankful for your help as I have wasted five hours on this new line issue :(</p>