即時通訊在開發由問題和多個單選按鈕組成的應用程序的最後部分,我知道如何插入每個單選按鈕的值,但現在我試圖插入所有的單選按鈕的值的選擇只需點擊按鈕插入,但我有這個錯誤:java.lang.ILLegalStateException : could not find a method ajouter (View) in activity class
。插入很多值單選按鈕,只需點擊一下
請問你有什麼想法嗎?
public class MainActivity extends Activity {
DBAdapter db = new DBAdapter(this);
int x=0;
int y=0;
int z=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db.open();
// RadioGroup radio =(RadioGroup)findViewById(rm_25_1);
RadioButton rad0 = (RadioButton) findViewById (R.id.rm_25_1_1);
RadioButton rad1 = (RadioButton) findViewById (R.id.rm_25_1_2);
// RadioGroup Télévision =(RadioGroup)findViewById(rm_25_2);
RadioButton tel0 = (RadioButton) findViewById (R.id.rm_25_2_1);
RadioButton tel1 = (RadioButton) findViewById (R.id.rm_25_2_2);
// RadioGroup Réfrigérateur =(RadioGroup)findViewById(rm_25_3);
RadioButton ref0 = (RadioButton) findViewById (R.id.rm_25_3_1);
RadioButton ref1 = (RadioButton) findViewById (R.id.rm_25_3_2);
}
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.rm_25_1_1:
if (checked)
x=0;
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
break;
case R.id.rm_25_1_2:
if (checked)
x=1;
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
break;
case R.id.rm_25_2_1:
if (checked)
y=0;
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
break;
case R.id.rm_25_2_2:
if (checked)
y=1;
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
break;
case R.id.rm_25_3_1:
if (checked)
z=0;
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
break;
case R.id.rm_25_3_2:
if (checked)
z=1;
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
}
Button bton = (Button)findViewById(R.id.ajout_un);
bton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ajouter(v);
Toast.makeText(getApplicationContext(), "Données enregistrées!!! =)", Toast.LENGTH_LONG).show();
}
public void ajouter(View v) {
db.insertcc(x,y,z);
}
});
}}
下面是XML文件:
<TextView
android:id="@+id/qm_25_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
style = "@style/question"
android:text=".1.Radio : "
/>
<RadioGroup
android:id="@+id/rm_25_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_marginTop="12dp"
android:background ="#FFF8DC"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rm_25_1_1"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:text="OUI" />
<RadioButton
android:id="@+id/ rm_25_1_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:text="NON" />
</RadioGroup>
<TextView
android:id="@+id/qm_25_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
style = "@style/question"
android:text=".2. Télévision :"
/>
<RadioGroup
android:id="@+id/rm_25_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_marginTop="12dp"
android:background ="#FFF8DC"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rm_25_2_1"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:text="Oui" />
<RadioButton
android:id="@+id/ rm_25_2_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:text="Non" />
</RadioGroup>
<TextView
android:id="@+id/qm_25_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
style = "@style/question"
android:text=".3. Réfrigérateur :"
/>
<RadioGroup
android:id="@+id/rm_25_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:layout_marginTop="12dp"
android:background ="#FFF8DC"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rm_25_3_1"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:text="Oui" />
<RadioButton
android:id="@+id/rm_25_3_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:text="Non" />
</RadioGroup>
<Button
android:id="@+id/ajout_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="ajouter"
android:layout_marginTop="26dp"
android:layout_marginLeft="150dp"
android:text="ENREGISTRER"
android:textStyle="bold" />
我試過這個解決方案,插入完成,但只有初始值!我試圖根據所選的單選按鈕更改值,是否有可能?感謝努力 –
所以你在想什麼解決方案?我怎麼能在我的數據庫中插入不同單選按鈕的值。 –
我歡迎任何解決問題的建議或想法:) –