Edittext Multiline with lines separated by dashes

Asked

Viewed 133 times

0

All right?

I’d like you to help me with something: I would like to have an Edittext with Multilines divided into lines.

What I mean is this: When we create a multiline Edittext (let’s put as an example a multiline with 4 lines), it leaves that dash below to type down there on the fourth line, and all the other 3 lines above it are a blank space. I would like to have 4 of these strokes, one for each line of my multiline, as if they were 4 Edittext one under the other.

I thought to do exactly as I said above, use 4 Edittext and then at the time to send the data do: Edittext1 + Edittext2 + Edittext3 + Edittext4; however, I do not know how would be the issue to arrive at the end of Edittext1 and already descend to 2 automatically.

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

1 answer

1


Good morning tries to create a component that extends Edittext and overwrite onDraw to draw lines, as an example 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 with.exemplo.seupackage.Linededittext

This suggestion has been withdrawn from here.

I hope I’ve helped.

  • Hello friend. First thanks for the help. I created this class that you said "Linededittext", and went to the xml of my Activity and changed Edittext to "with.exemplo.meupacote.Linededittext" as you suggested, but there are some errors in the preview: "The following classes could not be found". And the class has already been created, you know how to solve this? Thank you.

  • Friend, a thousand excuses. It was with error more I managed to give "build" in the project. Now it’s the way I wanted. I haven’t tried it yet, but it’s the way I wanted it. Thank you so much for the help...I will give the final test here and left the final comment to finalize the topic. Thank you so much.

  • It worked perfectly expensive. Thank you so much for your help.

  • Beauty, mark the answer as the right answer heheh thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.