EditText in onDraw()
I am aware of how to add EditText but not in the onDraw() function.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new GaugeAnimation((this),10));
EditText input = (EditText) findViewById(R.id.input);
input.setText("hello");
}
The above will not work, also, the below doesn't work either:
@Override
public void onDraw(Canvas c){
EditText input = (EditText) findViewById(R.id.input);
input.setText("h开发者_运维技巧i");
}
so how can i do this? i would basically like to add an editable text box but because i am not using:
setContentView(new R.layout.main);
its messing up. Any suggestions?
i tried:
public class GaugeAnimation extends View{
public GaugeAnimation(Context context, int value){
EditText input = new EditText(context);
input.setId(R.id.input);
}
}
but it still doesn't work what am i doing wrong?
When you construct your GaugeAnimation
view, make sure it calls setId(R.id.input)
for the EditText view you want to use for input. Then your first method will work.
You should be aware that you should not make updates to UI elements from a view's onDraw
method like you tried.
I guess you have to inflate the edittext to a view to be able to use it. Without inflating, your edittext isnt instantiated yet.
精彩评论