我還在將一個J2ME應用程序移植到Android,現在我的問題在於GUI。 對於我所看到的,Android的活動是偉大的,但我的J2ME充滿經典:SwitchDisplayable a la Android
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
Display display = getDisplay();
if (alert == null)
display.setCurrent(nextDisplayable);
else
display.setCurrent(alert, nextDisplayable);
}
我不能讓每一個可顯示一個活動,所以我想和視圖替換它們。我嘗試過,但它不起作用,應用程序不會更改屏幕。
更新:
謝謝回答,而是放在人vews內的FrameLayout,仍然一無所獲。這是我測試的核心代碼,這樣你就可以檢查出來:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView t = (TextView)findViewById(R.id.text); // Shows "Hi"
showDialog(); // it just shows a dialog asking if the user wants to change screen
}
showDialog() {
// in OnClick()... i do the following, and here is where it fails, i tried so far:
TestView testv= new MarcoLoco(MFActivity.this);
setContentView(testv);
testv.invalidate();
testv.requestFocus();
testv.showMeSomething();
}
public class TestView extends View{
private Context context;
TextView tv;
public TestView(Context context) {
super(context);
this.context=context;
}
public void showMeSomething() {
tv = (TextView)findViewById(R.id.tessto); // it should show "Bye"
}
}
從屏幕上的「喜」自敗的OnClick後卻沒有出現,也沒有「再見」。
爲什麼,哦,爲什麼!?
感謝您的回答!它還沒有工作,我添加了一個代碼片段,所以你都可以看到它。 – ferostar 2010-11-25 21:05:41
@Peter我添加了一個簡短的示例程序,切換2個文字瀏覽 – getekha 2010-11-25 21:48:21