EditText Multiline with lines separated by dashes

0

Alright?

I would like you to help me with one thing: I would like to have an EditText with Multilines split into lines.

What I want to say is this: When we create an EditText multiline (let's say multiline with 4 lines as an example), it leaves that stroke underneath to type down in the fourth line, and all 3 other top lines are left blank. I would like to have 4 of these strokes, one for each line of my multiline, as if they were 4 EditText one underneath the other.

I thought of doing exactly as I said above, using 4 EditText and then at the time of sending the data do: EditText1 + EditText2 + EditText3 + EditText4; however, I do not know how it would be to get to the end of EditText1 and get down to 2 automatically.

If anyone has a suggestion, solution or if you have any questions, just send a message. Thank you.

    
asked by anonymous 29.08.2016 / 06:46

1 answer

1

Good morning try to create an extended component of EditText and override the onDraw to draw the lines, as shown below:

public class LinedEditText extends EditText {
    private Rect mRect;
    private Paint mPaint;

    // we need this constructor for LayoutInflater
    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);

        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(R.color.edit_note_line); //SET YOUR OWN COLOR HERE
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //int count = getLineCount();

        int height = getHeight();
        int line_height = getLineHeight();

        int count = height / line_height;

        if (getLineCount() > count)
            count = getLineCount();//for long text with scrolling

        Rect r = mRect;
        Paint paint = mPaint;
        int baseline = getLineBounds(0, r);//first line

        for (int i = 0; i < count; i++) {

            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
            baseline += getLineHeight();//next line
        }

        super.onDraw(canvas);
    }
}

In your xml instead of using EditText uses com.example.seupacote.LinedEditText

This suggestion has been removed from here .

I hope I have helped.

    
29.08.2016 / 13:17