Я новичок в разработке Android. Я пытаюсь создать игру tic tac toe, и в настоящее время я хочу, чтобы мои кнопки были помечены кликом X, но когда я запускаю программу и нажимаю кнопку, ничего не происходит. Мой файл activity.java ниже:Программа для Android не работает
package com.android.tictactoe;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class TictactoeActivity extends Activity implements Button.OnClickListener{
Button one, two, three, four, five, six, seven, eight, nine;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
one=(Button)findViewById(R.id.one);
one.setOnClickListener(this);
two=(Button)findViewById(R.id.two);
two.setOnClickListener(this);
three=(Button)findViewById(R.id.three);
three.setOnClickListener(this);
four=(Button)findViewById(R.id.four);
four.setOnClickListener(this);
five=(Button)findViewById(R.id.five);
five.setOnClickListener(this);
six=(Button)findViewById(R.id.six);
six.setOnClickListener(this);
seven=(Button)findViewById(R.id.seven);
seven.setOnClickListener(this);
eight=(Button)findViewById(R.id.eight);
eight.setOnClickListener(this);
nine=(Button)findViewById(R.id.nine);
nine.setOnClickListener(this);
}
public void OnClick(Button button, int CheckedId){
if(CheckedId==R.id.one && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.two && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.three && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.four && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.five && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.six && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.seven && button.getText().equals("")){
button.setText("X");
}
else if(CheckedId==R.id.eight && button.getText().equals("")){
button.setText("X");
}
button.setText("X");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
моего main.xml ниже:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" >
<TableRow>
<TextView
android:text="Fizzle TicTacToe"
android:textStyle="bold"
android:textSize="30dip"
android:textColor="#ffaa88"
/>
</TableRow>
<TableRow>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/one"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/two"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/three"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
</TableRow>
<TableRow>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/four"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/five"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/six"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
</TableRow>
<TableRow>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/seven"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/eight"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
<Button
android:textColor="#440000"
android:textSize="40dip"
android:textStyle="bold"
android:text=""
android:id="@+id/nine"
android:layout_span="1"
android:layout_width="0dip"
android:layout_height="100dip"
android:layout_weight="30"/>
</TableRow>
</TableLayout>