0

I have a LinearLayout as below.

<LinearLayout
        android:id="@+id/messageLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp" 
        android:orientation="horizontal" />

Into this layout, dynamic TextViews are added at runtime. But before inserting at runtime I tried adding 5 texviews manually. This is how it looks like.

enter image description here

The layout for those textview is

<TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

I need the last text to gracefully follow normally rather than just breaking down as in the above image.

Where am I wrong? Could you help me figure this out?

EDIT

I have a message to display. For instance, England beats Australia in the final championship. Those bold texts have some ids attached which when clicked opens a dialog. So I break the text and add them as different TextViews so I could easly attach an onClickListener. I need the message to look one single text. Hope it makes more sense now.

EDIT 2

I used clickableSpan as a get around.

SpannableString spannableString = new SpannableString(message);
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View widget) {
        Log.i(TAG_NAME, "clickable span...");
    }
};

spannableString.setSpan(clickableSpan, 0, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(clickableSpan, 30, 40, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

All I am trying to do is add multiple span to a textview. However, it looks like only last span is working. Where am I going wrong?

Renjith
  • 3,457
  • 5
  • 46
  • 67
  • What do you mean by _"last text to gracefully follow normally"_? Should it go to the next line? Should it go out of the screen? Should all of them shrink to fit this one.. (what happens if there are more textviews than shown in picture..)? – Amulya Khare Nov 04 '13 at 11:50
  • 1
    You should not be having multiple text views. Use `ClickableSpan` instead. It will make your life easier.. http://stackoverflow.com/a/10697453/827110 So basically, one textview which has `bold` parts that are `clickable`.. sounds good? – Amulya Khare Nov 04 '13 at 11:54
  • Thanks for the reply! so how do you identify which text is clicked? say when I click England. Clickable span works well for static texts. not sure about dynamic texts. – Renjith Nov 04 '13 at 11:59
  • So each word, (England, Australia..) is a `ClickableSpan` which has its own `OnClickListener` so you will know – Amulya Khare Nov 04 '13 at 12:02
  • lemme play with it! keep you posted! Thanks for the comment – Renjith Nov 04 '13 at 12:06
  • @Amulya Khare Can you check the Edit 2? – Renjith Nov 04 '13 at 14:25
  • 1
    @Renjith: I think one span can only be added once. Try creating a second one... – tilpner Nov 04 '13 at 15:01
  • @StackOverflowException yeah, that's the culprit! Thanks! – Renjith Nov 04 '13 at 15:28

1 Answers1

0

Give weight to each textView as 1

Try this:

<TextView
            android:id="@+id/textView5"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:layout_weight="1" 
            android:textAppearance="?android:attr/textAppearanceSmall" />    

Hope this works

Manishika
  • 5,478
  • 2
  • 22
  • 28