1,2,3 순서대로누르기
<?xml version="1.0" encoding="utf-8"?>
<!-- activity_main.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="1dp"
android:layout_weight="1"
android:text="1"
android:textSize="30dp"/>
<Button
android:id="@+id/b2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="1dp"
android:layout_weight="1"
android:text="2"
android:textSize="30dp"/>
<Button
android:id="@+id/b3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="1dp"
android:layout_weight="1"
android:text="3"
android:textSize="30dp"/>
</LinearLayout>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="게임 중"
android:textSize="30dp"
android:layout_gravity="center"
android:textColor="#0000ff"/>
</LinearLayout>
// MainActivity.java
public class MainActivity extends AppCompatActivity {
int[] arr = new int[4];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arr[0] = 1;
for (int i=1; i<4; i++)
{
arr[i] = i;
}
Button b1 = findViewById(R.id.b1);
Button b2 = findViewById(R.id.b2);
Button b3 = findViewById(R.id.b3);
TextView textView = findViewById(R.id.tv);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (arr[0] == 1)
{
arr[0]++;
textView.setText(Integer.toString(arr[0]) + "누를차례");
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (arr[0] == 2)
{
arr[0]++;
textView.setText(Integer.toString(arr[0]) + "누를차례");
}
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (arr[0] == 3)
{
arr[0]++;
textView.setText("게임끝");
}
}
});
}
}