是新的android,我很想知道如何使我喜欢当我点击button1,然后button2文本视图将显示1 2 ,,,但如果我点击button2然后button1它会显示2 1如何制作一个排序字母作为字母
这是我的代码,但现在当我单击button然后按钮2,或者如果我点击BUTTON2然后BUTTON1它显示了同样的,, plz帮助我 感谢名单。
现在我做了它使用getText & setText其工作,因为我想要但条件,如果它的正确与否不工作PLZ帮助!它有什么问题,我的方法是否正确?
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// Full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.wordgame2);
bu1 = (Button) findViewById(R.id.bu1);
bu2 = (Button) findViewById(R.id.bu2);
bu3 = (Button) findViewById(R.id.bu3);
bu4 = (Button) findViewById(R.id.bu4);
bu5 = (Button) findViewById(R.id.bu5);
t1 = (TextView) findViewById(R.id.t1);
i1 = (ImageView) findViewById(R.id.i1);
i2 = (ImageView) findViewById(R.id.i2);
bu1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
t1.setText(t1.getText()+" "+bu1.getText());
}
});
bu2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
t1.setText(t1.getText()+" "+bu2.getText());
}
});
bu3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
t1.setText(t1.getText()+" "+bu3.getText());
}
});
bu4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
t1.setText(t1.getText()+" "+bu4.getText());
}
});
bu5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(t1.getText().toString().equals("a b c d")) //this is not working
{
i1.setVisibility(View.VISIBLE);
i2.setVisibility(View.INVISIBLE);
}
else {
i2.setVisibility(View.VISIBLE);
i1.setVisibility(View.INVISIBLE);
}
}
});
}
7月4日至21日:00:48.690:E/AndroidRuntime(23874):致命异常:主 7月4日至21日:00:48.690:E/AndroidRuntime(23874):java.lang中。 RuntimeException:无法启动活动ComponentInfo {com.arabicalphabets.reham/com.arabicalphabets.reham.Wordgame2}:java.lang.NullPointerException 04-21 07:00:48.690:E/AndroidRuntime(23874):at android.app。 ActivityThread.performLaunchActivity(ActivityThread.java:1970) 04-21 07:00:48.690:E/AndroidRuntime(23874):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) 04-21 07:00: 48.690:E/AndroidRuntime(23874):在android.app.ActivityThread.acces S $ 600(ActivityThread.java:127) 04-21 07:00:48.690:E/AndroidRuntime(23874):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1161) 04-21 07:00 :48.690:E/AndroidRuntime(23874):at android.os.Handler.dispatchMessage(Handler.java:99) 04-21 07:00:48.690:E/AndroidRuntime(23874):at android.os.Looper.loop (Looper.java:137) 04-21 07:00:48.690:E/AndroidRuntime(23874):at android.app.ActivityThread.main(ActivityThread.java:4512) 04-21 07:00:48.690:E/AndroidRuntime(23874):at java.lang.reflect.Method.invokeNative(Native Method) 04-21 07:00:48.690:E/AndroidRuntime(23874):at java.lang.reflect.Method.invoke(Method。 java:511) 04-21 07:00:48.690:E/AndroidRuntime(23874):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:982) 04-21 07:00:48.690:E/AndroidRuntime(23874):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) 04-21 07:00:48.690:E/AndroidRuntime 23874):at dalvik.system.NativeStart.main(Native Method) 04-21 07:00:48.690:E/AndroidRuntime(23874):引起:java.lang.NullPointerException 04-21 07:00:48.690: E/AndroidRuntime(23874):at com.arabicalphabets.reham.Wordgame2.onCreate(Wordgame2.java:36) 04-21 07:00:48.690:E/AndroidRuntime(23874):at android.app.Activity.performCreate E/AndroidRuntime(23874):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052) 04-21 07:00:48.690:E/AndroidRuntime(23874) AndroidRuntime(23874):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934) 7月4日至21日:00:48.690:E/AndroidRuntime(23874):...... 11多个
需要追加,使用'getText'和'setText'到使用TextView的内容 – 2013-04-20 00:36:20
okie ,,请你给我看一些例子吗? – 2013-04-20 00:38:58
不,自己想想,这个作业是最简单的一个。 – 2013-04-20 00:40:56