私はその時点でユーザーログインとしてアクティビティにログインしてラジオボタンをデフォルトでオンにしたいと思っていますアクティブなボタンセットは自動的にチェックされ、アクティビティの設定に移動してラジオボタンの選択を変更すると、ユーザーがアクティビティを設定する際に選択します。他のアクティビティでラジオボタンをデフォルトに設定する方法は?
コード:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
// String radiodefault=R.id.Active;
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if(checkedId == R.id.Active) {
Toast.makeText(getApplicationContext(), "choice: Active",
Toast.LENGTH_SHORT).show();
}
else if (checkedId == R.id.Inactive)
{
Toast.makeText(getApplicationContext(), "choice: Inactive",
Toast.LENGTH_SHORT).show();
}
}
});
active = (RadioButton) findViewById(R.id.Active);
inactive = (RadioButton) findViewById(R.id.Inactive);
button = (Button)findViewById(R.id.chooseBtn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedId = radioGroup.getCheckedRadioButtonId();
// find which radioButton is checked by id
if(selectedId == active.getId()) {
Toast.makeText(Settings.this,"Active is selected",Toast.LENGTH_LONG).show();
}
else if(selectedId == inactive.getId())
{
Toast.makeText(Settings.this,"Inactive is selected",Toast.LENGTH_LONG).show();
shareprefernceを使用して、ラジオボタンのブール値を格納しようとします。そして、SharePrefernceを使用してログアクティビティに設定します.... – sushildlh