我创建了(我以为是)一个简单的JAVA纸牌游戏。在JAVA中,游戏加载布局(框架)并显示包含像每个玩家的持卡人图像的方形的ImageButton。然后持卡人将随机卡片逐一填充。Android布局只显示方法完成后
所以,我在Android中onCreate方法,我最初的布局包括与卡持有者图像的卡片,然后我跑在onCreate方法来处理该名片的方法。我有的问题是最初的布局根本没有出现。显示的是持卡人已经填充的最终布局。该程序甚至没有显示他们,因为他们正在单独处理我认为可能需要运行AsyncTask,但我真的没有在我的交易方法中似乎需要它的任何“主要”指示。
我是一个相对新手到Android开发,我想我想知道,如果这么简单的事情要挂我原来的布局,主要应用程序指令去哪里,如果不是在从onCreate方法调用的方法?为什么它不像仅仅显示我的原始布局那么简单,然后继续UI线程和逐一更新卡片?
更新:
不幸的是,它仍然无法正常工作。我的onCreate看起来是这样的:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
player1Card1B = (ImageButton) findViewById(R.id.p1C1Bref);
player1Card2B = (ImageButton) findViewById(R.id.p1C2Bref);
player1Card3B = (ImageButton) findViewById(R.id.p1C3Bref);
player2Card1B = (ImageButton) findViewById(R.id.p2C1Bref);
player2Card2B = (ImageButton) findViewById(R.id.p2C2Bref);
player2Card3B = (ImageButton) findViewById(R.id.p2C3Bref);
player3Card1B = (ImageButton) findViewById(R.id.p3C1Bref);
player3Card2B = (ImageButton) findViewById(R.id.p3C2Bref);
player3Card3B = (ImageButton) findViewById(R.id.p3C3Bref);
player4Card1B = (ImageButton) findViewById(R.id.p4C1Bref);
player4Card2B = (ImageButton) findViewById(R.id.p4C2Bref);
player4Card3B = (ImageButton) findViewById(R.id.p4C3Bref);
newDeckCard = (ImageButton) findViewById(R.id.newCardDeckBref);
discardDeckCard = (ImageButton) findViewById(R.id.discardCardDeckBref);
knockButton = (ImageButton) findViewById(R.id.knockBref);
player1Card1B.setOnClickListener(this);
player1Card2B.setOnClickListener(this);
player1Card3B.setOnClickListener(this);
newDeckCard.setOnClickListener(this);
discardDeckCard.setOnClickListener(this);
knockButton.setOnClickListener(this);
}
and my onStart like this:
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
shuffle();
deal();
}
我只是得到一个白色的屏幕,上面写着“主”,然后最终卡被显示为已填充。我甚至没有得到在onCreate方法中读取的占位符。当我删除deal()方法时,占位符显示出来。当我把它放回去时,占位符卡片不显示出来,只有分发的卡片出现。
我认为在onStart()可能是一个更好的选择,为的onResume(也)被当应用程序返回到前台叫......你可能不希望再处理这个情况。 – CSmith 2012-08-06 20:30:22
@CSmith - 好点。 – mportuesisf 2012-08-06 20:32:33