Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get text input on Canvas?

I'm new in the Android world and I have a very annoying problem. In my program I use the Android Canvas. I'd like to add an EditText element, or something like that, to get user text inputs. Can you help me find a way to solve this problem?

Thanks for the answers.

like image 542
user1850215 Avatar asked Nov 24 '12 21:11

user1850215


1 Answers

Initially, you cannot place any edit text or buttonsusig canvas. Instead, you have to draw it. So create a custom layout and draw that layout with canvas

Try this, It might help you. in onDraw(..)

   LinearLayout lL = new LinearLayout(context);

   EditText editTextView = new EditText(context); 

   editTextView.setVisibility(View.VISIBLE);
   lL.addView(editTextView);

    lL.measure(canvas.getWidth(), canvas.getHeight());
    lL.layout(0, 0, canvas.getWidth(), canvas.getHeight());

    // placing the edit text at specific co-ordinates:
    //canvas.translate(0, 0);
    layout.draw(canvas);

And take a look at this another example : Click here

It gives another way of adding views

like image 69
RajeshVijayakumar Avatar answered Oct 31 '22 06:10

RajeshVijayakumar