I have two classes A and B A is main activity class and B is View class. Now I am calling View by setcontentview. when the view is active and i am drawing on it . I want the activity class is active so how do i do that ?
public class A extends Activity {
B b;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.button);
b = new B(this);
Button but = (Button) findViewById(R.id.showView);
but.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(drawView);
drawView.requestFocus();
}
});
}
}
public class b extends View implements OnTouchListener {
public DrawView(Context context) {
super(context);
setFocusable(true);
mContext = context;
setFocusableInTouchMode(true);
this.setBackgroundColor(Color.WHITE);
this.setOnTouchListener(this);
paint.setColor(Color.GRAY);
paint.setAntiAlias(true);
}
public void onDraw(Canvas canvas) {
mCanvas = canvas;
draw something
}
}
setContentView()replaces the entire view of theActivity. If you want to go back to the old view, callsetContentView()again with the old view again. By convention though, this is bad. Generally you only do one view per activity.