我有和活动它有两个微调....
例如:第一个旋转器有*印度*巴基斯坦*孟加拉国 第二个旋转器有*印度*巴基斯坦*孟加拉国当我们选择第一个旋转孟加拉国和第二个旋转印度,然后点击提交它必须去一个新的活动叫BDTOINDActivity.java
当我们选择第一个旋转器孟加拉国和第二个旋转器巴基斯坦然后点击提交它必须去一个新的活动电话BDTOIPAKActivity.java
答案 0 :(得分:1)
与微调器的值进行比较很简单 请看这个有用的答案:https://stackoverflow.com/a/13856029/7699710
我也在这里粘贴代码:
Spinner mySpinner1 = (Spinner)findViewById(R.id.spinner1);
String txtFromSpinner1 = mySpinner1.getSelectedItem().toString();
Spinner mySpinner2 = (Spinner)findViewById(R.id.spinner2);
String txtFromSpinner2 = mySpinner2.getSelectedItem().toString();
定义此微调器后,执行以下操作:
if (txtFromSpinner1.equals(txtFromSpinner2))
{
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);
}
答案 1 :(得分:0)
获取微调器的值,创建完整的活动类名称并开始活动。
//activity field
Map<String, String> map = new HashMap<>();
//onCreate
map.put("india", "IND");
map.put("pakistan", "PAK");
map.put("bangladesh", "BD");
//on submit
String fromStr = fromSpinner.getSelectedItem().toString();
String toStr = toSpinner.getSelectedItem().toString();
String packagePrefix = "our.package.name.";
String activityName = packagePrefix + map.get(fromStr) + "TO" + map.get(toStr) + "Activity";
Class<?> activityClass = null;
try {
activityClass = Class.forName(activityName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent(this, activityClass);
startActivity(intent);
答案 2 :(得分:0)
您可以执行以下操作:
submit = (Button)findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//First get the selected country name
String sp1Val = spinner1.getSelectedItem().toString();
String sp2Val = spinner2.getSelectedItem().toString();
// Then compare both spinner values:
if(sp1Value.equals("Bangladesh") && sp2Val.equals("India")){
Intent i = new Intent(MainActivity.this, BDTOINDActivity.class);
startActivity(i);
}
//Do the rest of them as same
}
});
希望这有帮助