我有两个类A和B A是主要活动类,B是View类。现在我通过setcontentview调用View。当视图处于活动状态并且我正在绘制它时。我希望活动类是活动的,所以我该怎么做?
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
}
}
答案 0 :(得分:2)
setContentView()
取代了Activity
的整个视图。如果您想返回旧视图,请再次使用旧视图再次呼叫setContentView()
。按惯例,这很糟糕。通常,每个活动只能执行一个视图。