I am trying to add an editText box to my android project. This project is done almost entirely with Java (barely any xml), so I would like to know how to get this done in Java. My current implementation which is getting a runtime error is as follows:
public class MainMenu extends View{
EditText editText;
public MainMenu(Context context) {
super(context);
EditText editText = new EditText(context);
editText.setDrawingCacheEnabled(true);
editText.setText("My Text");
editText.setWidth(180);
editText.setBackgroundColor(Color.WHITE);
}
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
editText.draw(canvas);
invalidate();
}
}
Can anyone point out what is wrong and possibly offer a solution using Java?