2016-11-18 11 views
-1

私は2つの紛争のある2つの郵便がある場合、それぞれ異なる投稿がある投票申込書を作成しようとしています。データベースに記録する人を1人選択するといいです。ここで [その出場者とポストのdisgnの一部は] XMLコードの一部です:アンドロイドスタジオを使用して、ラジオボタンの値を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を取ると考えていますか?あなたは、これは私が助けることができるすべてであるJavaコードのいずれかを共有していなかったので、

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

は、あなたのデータベースハンドラのために、この

contentValues.put(table_name, choice); 

ようなものをやってみてください。

構造体とSQLiteDatabaseHelperを実装することをお勧めします。

+0

ありがとうございました。問題は、私がその部分を本当によく理解していないので、私が.javaコードを書かなかったことです。 – Dunn

+0

Googleで例を探すことをおすすめします。私は、例を見て、それらの例のロジックとコードを自分のプログラムに組み込む方法を見つけることは、プログラミングを学び始めたばかりのときに非常に役に立ちました。 –

+0

Javaコードを投稿するときにKaze Notusに尋ねることができれば、この問題を理解する上で本当に役に立ちます。 – Dunn

関連する問題