可能重复:
Java String.equals与==
我知道这是一个愚蠢的问题,但为什么这段代码不起作用.
boolean correct = "SampleText" == ((EditText)findViewById(R.id.editText1)).getText().toString();
if(correct) ((TextView)findViewById(R.id.textView1)).setText("correct!");
else ((TextView)findViewById(R.id.textView1)).setText("uncorrect!");
Run Code Online (Sandbox Code Playgroud)
关键是要检查"editText1"的内容是否等于"Sample Text"
我想在我的LibGDX Android游戏中使用Google Play游戏服务API的成就和排行榜.我唯一能做的就是从Game Services开发者网站上运行示例.我一直试图在我的项目中使用这段代码很多天,我什么都没有.我也试过按照这个教程http://helios.hud.ac.uk/u1070589/blog/?p=202但我没有"主要游戏类(从ApplicationListener扩展的那个)"这是在步骤7中需要.我只有
这是来自MainActivity.java的onCreate方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
thingy=this;
RelativeLayout layout=new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView=initializeForView(new DogeJump(this),false);
adView=new AdView(this,AdSize.IAB_MRECT,"ca-app-pub-XXXXXXX363095/9011689567");
adView.loadAd(new AdRequest());
layout.addView(gameView);
RelativeLayout.LayoutParams adParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView,adParams);
setContentView(layout);
//initialize(new DogeJump(this),false);
}
Run Code Online (Sandbox Code Playgroud) 我需要在我的Android游戏中使用"hypot"方法,但是eclipse说没有这样的方法.这是我的代码:
import java.lang.Math;//in the top of my file
float distance = hypot(xdif, ydif);//somewhere in the code
Run Code Online (Sandbox Code Playgroud)