# AN25 課題No.02 ###### tags: `課題` AN25 課題02 代表的なウィジェットプログラム 期限:2021.05.27 あまりきれいなコードじゃないけど activity_main.xml ```xml= <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/myTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Select One..." /> <RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Android" android:onClick="radioMethod" /> <RadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="BlackBerry" android:onClick="radioMethod" /> <RadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="iPhone" android:onClick="radioMethod" /> </RadioGroup> <RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="グーグル" android:onClick="radioMethods" /> <RadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="マイクロソフト" android:onClick="radioMethods" /> <RadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="アップル" android:onClick="radioMethods" /> </RadioGroup> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox View" android:onClick="buttonMethod" /> </LinearLayout> ``` MainActivity.java ```java= package nhs00650.hal.ac.myradiobutton; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.RadioButton; import org.w3c.dom.Text; public class MainActivity extends AppCompatActivity { private TextView aTextView; int a; int b; int i; int g; int m; int ap; String st = "non Selected"; String str = "non Selected"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); aTextView = (TextView)findViewById(R.id.myTextView); a = 0; b = 0; i = 0; g = 0; m = 0; ap = 0; } public void radioMethod(View myRadioButton) { RadioButton aRadioButton = (RadioButton)myRadioButton; String s = (String)aRadioButton.getText(); if(s.equals("Android")) a = 1; else if(s.equals("BlackBerry")) b = 1; else if(s.equals("iPhone")) i = 1; } public void radioMethods(View myRadioButton) { RadioButton bRadioButton = (RadioButton)myRadioButton; String s = (String)bRadioButton.getText(); if(s.equals("グーグル")) g = 1; else if(s.equals("マイクロソフト")) m = 1; else if(s.equals("アップル")) ap = 1; } public void buttonMethod(View myButton){ if(a == 1) st = "Android Selected"; else if(b == 1) st = "BlackBerry Selected"; else if (i == 1) st = "iPhone Selected"; if(g == 1) str = "グーグル Selected"; else if(m ==1) str = "マイクロソフト Selected"; else if(ap == 1) str = "アップル Selected"; aTextView.setText(String.format(st + "\n" + str)); a = 0; b = 0; i = 0; g = 0; m = 0; ap = 0; } } ``` <span style="color: #ff3333">aaa</span> <span style="text-decoration: underline">aaa</span> ## 雑談 (0→やまぴ 1→みや 2→やすい 3→りょうくん)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up