I've got a TextView that crashes the app when trying to setText. I'm not using the XML layout and have set a custom view to handle everything. Obviously the app crashes when the screen is touched after the app is initalized.
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout lv = new LinearLayout(this);
lv.setOrientation(LinearLayout.VERTICAL);
mView = new MyView(this);
TextView tvX = new TextView(this);
lv.addView(tvX);
lv.addView(mView);
lv.setBackgroundColor(Color.GRAY);
tvX.setTextColor(Color.WHITE);
tvX.setText("Ahmad");
setContentView(lv);
mView.requestFocus();
public class MyView extends View {
private TextView tvX;
public void setTextView(TextView tv){
tvX = tv;
}
@Override public boolean onTouchEvent(MotionEvent event) {
tvX.setText("123");
}
Any help is appreciated!
EDIT 1
08-27 00:39:49.859: E/MessageQueue-JNI(510): at co.projx.touchpaint.TouchPaint$MyView.onTouchEvent(TouchPaint.java:286)
08-27 00:39:49.874: E/AndroidRuntime(510): at co.projx.touchpaint.TouchPaint$MyView.onTouchEvent(TouchPaint.java:286)