views:

42

answers:

1

I have a long text and i want it to be displayed with a TextView. The text i have is much longer than the available space. However i don't want to use scrolling, but ViewFlipper to flip to the next page. How can i retrieve the lines from the first TextView that are not shown because the view is to short so that i can paste them into the next TextView?

Edit: I found the Solution to my Problem. I simply have to use a custom View with a StaticLayout like this:

public ReaderColumView(Context context, Typeface typeface, String cText) {
        super(context);
        Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        dWidth = display.getWidth(); 
        dHeight = display.getHeight();

        contentText = cText;

        tp = new TextPaint();
        tp.setTypeface(typeface);
        tp.setTextSize(25);
        tp.setColor(Color.BLACK);
        tp.setAntiAlias(true);

        StaticLayout measureLayout = new StaticLayout(contentText, tp, 440, Alignment.ALIGN_NORMAL, 1, 2, true);
        Boolean reachedEndOfScreen = false;
        int line = 0;
        while (!reachedEndOfScreen) {
            if (measureLayout.getLineBottom(line) > dHeight-30) {
            reachedEndOfScreen = true;
            fittedText = contentText.substring(0, measureLayout.getLineEnd(line-1));
            setLeftoverText(contentText.substring(measureLayout.getLineEnd(line-1)));
            }

            line++;

        }
    }
protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        StaticLayout textLayout = new  StaticLayout(fittedText, tp, 440, Alignment.ALIGN_NORMAL, 1, 2, true);
        canvas.translate(20,20);
        textLayout.draw(canvas);
    }

Thats not optimized yet but you get the point. I hope it might help somebody like me with a similar problem.

A: 

ViewFlipper will not solve your problem, it will not work. Because in view flipper you have for each view different layout xml files. I think there are better solutions you could think about. E.g. when the user presses the text, which could be an extract of the long text, a dialog shows up and presents the whole text.

ArtWorkAD
The ViewFlipper is not the problem. My Problem is how to get the rest of the TextView. I need to exactly know how much text is already visible but i cant figure out how to do it.
par
well if you have a certain text view width you can get the length of the string that is visible first and then use it to substring your text
ArtWorkAD
but i dont have only one line, i have like 27 lines so i think width wont help me much does it?
par
well then use height, since you want a fixed number of lines the height is fixed too.
ArtWorkAD
how? are you sure you understand my problem?i have a textview:test = (TextView) vw.findViewById(R.id.ContentColum);test.setText(R.string.text);but R.string.text is to long for the textview. how can i use height to get the last visible word in textview or the index of the last visible character so that i can use something like substring?
par