0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidStudioでのRadioButtonについて

Last updated at Posted at 2016-01-30

選択したRadioButtonのandroid:text=の値をSQLiteのデータベースに
保存したいんですがやり方が解りません。
どうすればいいですか?

MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyOpenHelper helper = new MyOpenHelper(this);
final SQLiteDatabase db = helper.getWritableDatabase();

    final EditText nameText = (EditText) findViewById(R.id.editName);
    final EditText ageText = (EditText) findViewById(R.id.editAge);
    final EditText doText =(EditText)findViewById(R.id.editDo);
    final RadioGroup Waketa = (RadioGroup)findViewById(R.id.Bunrui);


    Button entryButton = (Button) findViewById(R.id.insert);
    entryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name = nameText.getText().toString();
            String age = ageText.getText().toString();
            String doing = doText.getText().toString();

            ContentValues insertValues = new ContentValues();
            insertValues.put("name", name);
            insertValues.put("age", age);
           insertValues.put("doing", doing);
            db.insert("person", name, insertValues);

        }

activity_main.xml

   <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Bunrui">

        <RadioButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="赤"
            android:onClick="onClickRadioButton"
            android:id="@+id/Syou1"/>
        <RadioButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="青"
            android:onClick="onClickRadioButton"
            android:id="@+id/Syou2"/>
        <RadioButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="白"
            android:onClick="onClickRadioButton"
            android:id="@+id/Syou3"/>
        <RadioButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="黒"
            android:onClick="onClickRadioButton"
            android:id="@+id/Syou4"/>
    </RadioGroup>
    <Button
        android:id="@+id/insert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editAge"
        android:text="登録" />

大体、関連しそうな部分は此処かと思っているのですが?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?