Question

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);
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top