2016-11-18 148 views
-1

我想創建一個投票應用程序,其中有不同的職位,其中有兩個職位每個都有兩個聯繫人。我希望當我選擇一個人記錄到數據庫。 [職位的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> 

回答

0

你有沒有考慮一個OnClickListener?

RadioButton radioButton; 
radioButton = (radioButton)findViewById(R.id.radioButton4); 
string choice = (String)radioButton.getText(); 

然後爲你的數據庫處理程序嘗試做這樣的事情

contentValues.put(table_name, choice); 

因爲你沒有分享任何java的代碼,這是所有我可以幫忙的。

我建議實現一個結構和一個SQLiteDatabaseHelper。

+0

謝謝kaze。問題是我沒有編寫.java代碼,因爲我不太瞭解該部分。 – Dunn

+0

我建議在Google上尋找示例。我發現,當我剛剛開始學習編程時,通過查看示例並找到將這些示例的邏輯和代碼合併到我自己的程序中的方法非常有用。 –

+0

現在,如果我可能會問Kaze Notus,當我發佈java代碼時,它會真的幫助解決這個問題 – Dunn

相關問題