2

in need to format several textview one after another like an unique block of text, there is a way to achieve this?

like this

__________________________
|                        |
|                        |
| aaaaaa bbbbbbbbbbbbbbb |
| bbbbbbbbbb cccccc dddd |
| ddddddddddddd.         |
|                        |

i can't put the textview in a LinearLayout because i will obtain this effect:

__________________________
|                        |
|                        |
| aaaaaa bbbbbbbbbbbbbbb |
|        bbbbbbbbbb      |
|                        |
|                        |

any idea?

UPDATE: RESOLVED WITH SPANNABLES

    String[] testString = { "this is a test ", "for testing click in different region", "of the textview"};
    LinearLayout linear = new LinearLayout(this);
    TextView textview = new TextView(this);
    textview.setMovementMethod(LinkMovementMethod.getInstance());
    SpannableStringBuilder builder = new SpannableStringBuilder();
    int start = 0;
    int end = 0;

    for (String span : testString) {
        start = end == 0 ? end : end + 1;
        end = start + span.length();
        final String spanned = span;
        builder.append(span);
        builder.setSpan(new ClickableSpan() {

            @Override
            public void onClick(View widget) {
                Log.e("Clicked on:", spanned);
            }
        }, start, end, 0);
        Log.e("TEST", span);
    }

    textview.append(builder);

    linear.addView(textview);
    setContentView(linear);
CLucera
  • 1,091
  • 11
  • 29

1 Answers1

3

you can use FlowLayout if you really need this. But if you can, you should use one textView and format text using spannables.

Leonidos
  • 10,482
  • 2
  • 28
  • 37
  • FlowLayout will make the textview shift in the new row from the beginning, in need to break the textview and make it start from the right of the preceding textview like in the example – CLucera Oct 23 '13 at 14:47
  • Then use spannables. What kind of formatting you want to apply? – Leonidos Oct 23 '13 at 14:51
  • i need to use every textview as a button (i need to click in a "paragraph" and make it selected) if you check the example number 1 if i clic on b, i need to change all the b textview color – CLucera Oct 23 '13 at 15:22
  • [use spannable](http://stackoverflow.com/questions/7570239/android-linkify-text-spannable-text-in-single-text-view-as-like-twitter-twee) – Leonidos Oct 23 '13 at 17:16