I am building an android app where the user paints some objects in the screen. One type of object is a Text object. The user creates the object by dragging his finger and the object is shown as a rectangle that can be moved/reshaped. When user taps the text object, I launch a new activity where user enters text which I return on the onActivityResult method.
Now I want to show the text in the object. I can have access to stuff as the coordinates of the Rectangle etc from my text class. What I want to do in essence, is to create a TextView (or EditText) programmatically and set its bounds as the bounds of my rectangle that my object is painted in. Is there a method that can help me do it?
(another approach would be to use the canvas.drawTextOnPath method in my text object. But this seems more complicated since my text might get out of the object, and I would also have to handle the multilines)
Thank you very much in advance!
EDIT: trying GAMA's approach
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case 1:
if (resultCode == Activity.RESULT_OK) {
String text=data.getStringExtra("text");
System.out.println(text);
TextView tv=new TextView(this);
//LayoutParams lp = new LayoutParams(new ViewGroup.MarginLayoutParams((int)texts.get(index).width,(int)texts.get(index).height));
LayoutParams lp = new LayoutParams(new ViewGroup.MarginLayoutParams(100,100));
//tv.setLayoutParams(lp);
//lp.setMargins((int)texts.get(index).Sx, (int)texts.get(index).Sy, (int)texts.get(index).Lx, (int)texts.get(index).Ly);
tv.setLayoutParams(lp);
tv.setTextSize(10);
tv.setTextColor(Color.RED);
tv.setText(text);
lp.setMargins(0,0,0,0);
//tv.setVisibility(View.VISIBLE);
System.out.println("got "+tv.getText());
}
break;
}
}
both prints show the text as expected but I do not see anything in the screen (tried to set it on the bottom left to begin with)