如何使用android studio将单选按钮的值保存到mysql数据库?

如何使用android studio将单选按钮的值保存到mysql数据库?,android,mysql,Android,Mysql,我正在尝试创建一个投票应用程序,其中有不同的帖子,其中有两个帖子,每个帖子有两个contastant。我希望当我选择一个人时,它会记录到数据库中。[与参赛者一起设计帖子的部分内容] 以下是xml代码的一部分: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <

我正在尝试创建一个投票应用程序,其中有不同的帖子,其中有两个帖子,每个帖子有两个contastant。我希望当我选择一个人时,它会记录到数据库中。[与参赛者一起设计帖子的部分内容] 以下是xml代码的一部分:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:text="@string/posts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:id="@+id/textView3"
        android:textStyle="normal|bold"
        android:textSize="30sp"
        android:layout_weight="0.03"
        android:textAlignment="center" />

    <TextView
        android:text="@string/chairman"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="31dp"
        android:id="@+id/textView4"
        android:textStyle="normal|bold" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="14dp"
        android:layout_weight="0.01"
        android:id="@+id/Chairman">

        <RadioButton
            android:text="@string/duncan_sirikwa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radioButton4"
            android:layout_weight="1.23" />

        <RadioButton
            android:text="@string/kosgei_kevin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radioButton3"
            android:layout_weight="1" />
    </RadioGroup>

您是否考虑过使用OnClick Listener

RadioButton radioButton;
radioButton = (radioButton)findViewById(R.id.radioButton4);
string choice = (String)radioButton.getText();
然后,对于您的数据库处理程序,尝试执行以下操作

contentValues.put(table_name, choice);
因为您没有共享任何java代码,所以我只能在这方面提供帮助


我建议实现一个结构和一个SQLiteDatabaseHelper。

谢谢kaze。问题是,我没有编写.java代码,因为我不太理解这一部分。我建议在google上查找示例。当我刚开始学习编程时,我发现查看示例并找到方法将这些示例的逻辑和代码合并到我自己的程序中非常有帮助。现在,如果我在发布java代码时问Kaze Notus,这真的会有助于理解这一点吗problem@Dunn哦我已经解决了这个难题。结果发现我试图用一种完全错误的方式解决我的问题。我应该删除这个问题@邓恩:我很抱歉。我以为这是我的老问题。对发布您的代码可以帮助我和其他人了解您是如何试图保存和解决问题的。