再次来到新手,感谢我对其他问题的帮助。 我有一切工作,但我的点击按钮我需要应用哪个无线电ID或数组微调器组从中拉出数组,soi可以转发到正确的页面。 我主要是遇到btn1的问题如何正确地构造&之后的if语句。 我们非常感谢任何指导。
找到解决方案!!! 贴在底部!! 串
<string name="prov_picker">Select a Province</string>
<string-array name="prov_array">
<item>-- Select Province --</item>
<item>British Columbia</item>
<item>Alberta</item>
<item>Saskatchewan</item>
<item>Manitoba</item>
<item>Ontario</item>
<item>Quebec</item>
<item>New Brunswick</item>
<item>Nova Scotia</item>
<item>Newfoundland</item>
</string-array>
<string-array name="prov1_array">
<item>-- Select Province --</item>
<item>British Columbia</item>
<item>Alberta</item>
<item>Saskatchewan</item>
<item>Manitoba</item>
<item>Ontario</item>
<item>Quebec</item>
<item>New Brunswick</item>
<item>Nova Scotia</item>
<item>Newfoundland</item>
</string-array>
<string name="radio1">Provincial</string>
<string name="radio2">Federal</string>
Java
mport android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Spinner;
import android.view.View;
public class CanProvselect extends Activity implements OnCheckedChangeListener {
/** Called when the activity is first created. */
private RadioGroup RadioProvs;
private Button btn1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.canprovselect);
btn1 = (Button)findViewById(R.id.button1);
RadioProvs = (RadioGroup) findViewById(R.id.rgProvs);
RadioProvs.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
ArrayAdapter<CharSequence> adapter = null;
final Spinner spinner = (Spinner) findViewById(R.id.spinner);
switch (checkedId) {
case R.id.radio_1 :
adapter = ArrayAdapter.createFromResource(
this, R.array.prov_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
//spinner.setOnItemSelectedListener(new OnItemSelected(
// ));
break;
case R.id.radio_2 :
adapter = ArrayAdapter.createFromResource(
this, R.array.prov1_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
//spinner.setOnItemSelectedListener(new OnItemSelected(
// ));
break;
}
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Spinner sp = (Spinner)findViewById(R.id.spinner);
String spinnerString = null;
spinnerString = sp.getSelectedItem().toString();
if (spinnerString.equalsIgnoreCase("British Columbia") && R.id.equals("radio_1")){
Intent myIntent = new Intent (v.getContext(), ProvBC.class);
startActivityForResult(myIntent, 0);
} else
if (spinnerString.equalsIgnoreCase("British Columbia") && R.id.equals("radio_2")){
Intent myIntent = new Intent (v.getContext(), FederalProvBC.class);
startActivityForResult(myIntent, 0);
}
}
});
}
}
解决方案
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Spinner sp = (Spinner)findViewById(R.id.spinner);
String spinnerString = null;
spinnerString = sp.getSelectedItem().toString();
if (spinnerString.equalsIgnoreCase("British Columbia") && (checkedId == R.id.radio_1)){
Intent myIntent = new Intent (v.getContext(), ProvBC.class);
startActivityForResult(myIntent, 0);
} else
if (spinnerString.equalsIgnoreCase("British Columbia") && (checkedId == R.id.radio_2)){
Intent myIntent = new Intent (v.getContext(), FederalProvBC.class);
startActivityForResult(myIntent, 0);
}
}
});
答案 0 :(得分:0)
大家好我所有人都找到了我的问题的解决方案..以为我会发布答案以防万一有人可能需要它。 单选按钮将选择不同的数组,提交按钮将重定向到页面