我有一個包含8個單選按鈕的4個活動的simpe表單。當一個活動被回答時,它會進入下一個活動,並且我希望在第四個活動中顯示已檢查的單選按鈕的結果。有人可以幫我添加單選按鈕的值並計算答案嗎? 我想創建一個心理學測試,每個單選按鈕必須有不同的值。將它們加起來會形成獨特的心理學概況。 以下是我的應用程序中的一個佈局和活動。 我是新來的,我很感激所有的幫助。謝謝!如何將值添加到單選按鈕並計算答案?
佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question_1"/>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioButton
android:id="@+id/radiobutton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/radio_1"/>
<RadioButton
android:id="@+id/radiobutton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/radio_2"/>
</RadioGroup>
</LinearLayout>
活動:
package com.example.app_test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioButton buttonOne = (RadioButton)findViewById(R.id.radiobutton1);
buttonOne.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
//Go to the activity for button 1 here
MainActivity.this.startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
}
});
RadioButton buttonTwo = (RadioButton)findViewById(R.id.radiobutton2);
buttonTwo.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
//Go to the activity for button 2 here
MainActivity.this.startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
但是如何在單擊一個按鈕時創建靜態變量?謝謝! – eeschimosu