MainActivity.java:從自定義佈局創建xml佈局。可能嗎?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setTitle(R.string.app_name);
setContentView(new SampleView(this));
}
}
SampleView.java:
public class SampleView extends View {
@Override
protected void onDraw(Canvas canvas) {
if (certaincondition = true) {
//add elements to canvas etc
} else {
//How do I do the below? The layout is defined in xml.
//I do not want to use Intent. Please help me
//create a layout from resource R.layout.idAbout and transfer control.
}
}
}
實際問題在這裏描述http://stackoverflow.com/questions/4926478/why-does-the-menu-button-in-the-emulator-show-all-the-activities-of-my-app 。因爲我無法修復它:作爲解決方法,我正在嘗試爲所有視圖使用相同的活動。 – hsbgowd 2011-02-07 21:06:06