auto Split string based on text width - Android java.lang

Android examples for java.lang:String Split

Description

auto Split string based on text width

Demo Code

import android.graphics.Paint;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static ArrayList<String> autoSplit(String contentStr, Paint p,
            float width) {
        ArrayList reList = new ArrayList();
        String[] tempSplit = contentStr.split("\\n+");

        for (int x = 0; x < tempSplit.length; ++x) {
            String content = tempSplit[x];
            if (content.length() > 0) {
                int length = content.length();
                float textWidth = p.measureText(content);
                if (textWidth <= width) {
                    reList.add(content);
                } else {
                    int start = 0;
                    int end = 1;
                    label163: for (; start < length;)
                        ;// www  .j  ava  2s. c om
                }

            }

        }

        return reList;
    }

}

Related Tutorials