如何使用android studio将单选按钮的值保存到mysql数据库?
问题描述:
我想创建一个投票应用程序,其中有不同的职位,其中有两个职位每个都有两个联系人。我希望当我选择一个人记录到数据库。 [职位的disgn与它的参赛者部] 下面是XML代码的一部分:如何使用android studio将单选按钮的值保存到mysql数据库?
<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>
答
你有没有考虑一个OnClickListener?
RadioButton radioButton;
radioButton = (radioButton)findViewById(R.id.radioButton4);
string choice = (String)radioButton.getText();
然后为你的数据库处理程序尝试做这样的事情
contentValues.put(table_name, choice);
因为你没有分享任何java的代码,这是所有我可以帮忙的。
我建议实现一个结构和一个SQLiteDatabaseHelper。
谢谢kaze。问题是我没有编写.java代码,因为我不太了解该部分。 – Dunn
我建议在Google上寻找示例。我发现,当我刚刚开始学习编程时,通过查看示例并找到将这些示例的逻辑和代码合并到我自己的程序中的方法非常有用。 –
现在,如果我可能会问Kaze Notus,当我发布java代码时,它会真的帮助解决这个问题 – Dunn