The examples in this article share Android rock-paper-scissors game for your reference. The specific content is as follows
Simple page jump and click event implementation...
-->
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:andro package="" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="" android:label="@string/app_name" > <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity> <activity android:name=""> </activity> </application> </manifest> AndroidManifest
-->
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">fight</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> <string name="player1">Party A</string> <string name="player2">Party B</string> <string name="choose1">Stone</string> <string name="choose2">Scissors</string> <string name="choose3">cloth</string> <string name="sure">Punch</string> <string name="again">Another round</string> </resources> --> fragment_main.xml <RelativeLayout xmlns:andro xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" tools:context="$PlaceholderFragment" > <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="36dp" android:text="@string/player1" android:textSize="30sp" /> <RadioGroup android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" > <RadioButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="@string/choose1" /> <RadioButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/choose2" /> <RadioButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/choose3" /> </RadioGroup> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/radioGroup1" android:layout_below="@+id/radioGroup1" android:layout_marginTop="14dp" android:text="@string/sure" /> <ImageView android: android:layout_width="120dp" android:layout_height="120dp" android:layout_above="@+id/radioGroup1" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:src="@drawable/b" /> </RelativeLayout>
--> activity_other.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ffffff" > <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="36dp" android:text="@string/player2" android:textSize="30sp" /> <RadioGroup android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" > <RadioButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="@string/choose1" /> <RadioButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/choose2" /> <RadioButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/choose3" /> </RadioGroup> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/radioGroup1" android:layout_below="@+id/radioGroup1" android:layout_marginTop="14dp" android:text="@string/sure" /> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/button1" android:visibility="invisible" android:layout_marginTop="14dp"/> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_centerHorizontal="true" android:visibility="invisible" android:text="@string/again" /> <ImageView android: android:layout_width="120dp" android:layout_height="120dp" android:layout_above="@+id/radioGroup1" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:src="@drawable/a" /> </RelativeLayout>
--> MainActivity
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends Activity { // Set a static variable to close the Activity public static MainActivity instance = null; private RadioGroup radioGroup1; private Button button1; private ImageView imageView1; @Override protected void onCreate(Bundle savedInstanceState) { // Represents the current activity instance = this; (savedInstanceState); setContentView(.fragment_main); radioGroup1 = (RadioGroup) findViewById(.radioGroup1); // Set the picture to be transparent // imageView1 = (ImageView) findViewById(.imageView1); // ().setAlpha(100); button1 = (Button) findViewById(.button1); (new MyButtonListener()); } class MyButtonListener implements OnClickListener { @Override public void onClick(View v) { // Get the selected RadioButton RadioButton radioButton = (RadioButton) findViewById(radioGroup1 .getCheckedRadioButtonId()); String radioText = ().toString(); Intent intent = new Intent(); ("checked", radioText); (, ); startActivity(intent); } } }
--> OtherActivity
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class OtherActivity extends Activity { private RadioGroup radioGroup1; private Button button1; private TextView textView2; private RadioButton radioButton; private Button button2; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_other); radioGroup1 = (RadioGroup) findViewById(.radioGroup1); button1 = (Button) findViewById(.button1); textView2 = (TextView) findViewById(.textView2); button2 = (Button) findViewById(.button2); (new MyButtonListener()); (new MyButtonListener1()); } class MyButtonListener implements OnClickListener { @Override public void onClick(View v) { radioButton = (RadioButton) findViewById(radioGroup1 .getCheckedRadioButtonId()); String buttonText = ().toString(); Intent intent = getIntent(); String checked = ("checked"); // Set View to visible (); (); String msg = "A:" + checked + "\n" + "B" + buttonText + "\n"; if ((checked)) { (msg + "draw"); } if (("Stone")) { if (("Scissors")) { (msg + "Party B wins"); } else if (("cloth")) { (msg + "Party A wins"); } } if (("Scissors")) { if (("cloth")) { (msg + "Party B wins"); } else if (("Stone")) { (msg + "Party A wins"); } } if (("cloth")) { if (("Stone")) { (msg + "Party B wins"); } else if (("Scissors")) { (msg + "Party A wins"); } } } } class MyButtonListener1 implements OnClickListener { @Override public void onClick(View arg0) { Intent intent = new Intent(); (, ); finish(); // Close the specified activity (); startActivity(intent); } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.