アンドロイドにWindowsペアゲーム(javaで書かれている)をインポートしていますが、 を実行しても、これを実行してもボタンは表示されません... (現在のところ私のコードはうまくいきませんそれは速いです)実行時にアンドロイド表示を作成する
ここで何がうまくいかないのですか?
package mgh;
import mgh.mgh.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.RelativeLayout;
public class mghActivity extends Activity implements OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new mghActivity();
}
public int numberOfClickes=0;
public card continueCard=null;
public int killedCards=0;
public card selectedCard=null;
public long spentTime=0;
public card[][] card=new card[4][4];
public void mghActivity(){
setTitle("pairs");
//setVisible(true);
//setSize(500,500);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AbsoluteLayout lay=new AbsoluteLayout(this);
int[] clr=new int[8];
short[] timesUsed=new short[8];
for (int i=0;i<=7;i++)
timesUsed[i]=0;
for (int i=0;i<=7;i++)
clr[i]= Color.rgb(((int)(Math.random()*2))*255,
((int)(Math.random()*2))*255,
((int)(Math.random()*2))*255);
for (int i=0;i<=3;i++)
for (int j=0;j<=3;j++){
int rnd=0;
while (timesUsed[rnd]>=2)
rnd=(int)(Math.random()*8)%8;
timesUsed[rnd]++;
card[i][j]=new card(this,clr[rnd]);
//card[i][j].setEnabled(false);
//AbsoluteLayout.LayoutParams mparams=new AbsoluteLayout.LayoutParams
//(lay.getWidth()/4,lay.getHeight()/4,(lay.getWidth()/4)*i,(lay.getWidth()/4)*j);
int m=40;
AbsoluteLayout.LayoutParams mparams=new AbsoluteLayout.LayoutParams
(m,m,m*i,m*j);
lay.addView(card[i][j],mparams);
card[i][j].setOnClickListener(this);
}
setContentView(lay);
}
public void onClick(View arg0) {
}
}
class card extends Button {///not completed
public int color;
public card(Context context,int color){
super(context);
this.color=color;
setBackgroundColor(color);
}
}
あなたの['AbsoluteLayout'](https://developer.android.com/reference/android/widget/AbsoluteLayout.html) - 非難されたクラスです_forever_、btw - 幅と高さが0になります画面上にレイアウトされます。 http://stackoverflow.com/questions/3591784/getwidth-and-getheight-of-view-returns-0 –
u .understoodに感謝 –
ああ、ええ、マークは、以下の答えにも良い点があります。私はそこに 'new'というキーワードを気付かなかった。それだけでは機能しません。メソッドを呼び出す必要があります。実行できない 'Activity'をインスタンス化せず、正しく動作させる必要があります。 –