我搜索所有相似的解决方案,但什么也没找到; 是否可以使用微调器移动到另一个活动? 我试图从switch case开始明确的意图,但它不起作用
这是我的代码:
//add new movie spinner and callback
ArrayList<String> addOptions = new ArrayList<String>();
addOptions.add("Add manually");
addOptions.add("Add via web");
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,addOptions);
addMovieSpinner.setAdapter(spinnerAdapter);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
addMovieSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long i) {
switch (position) {
case 0:
Intent intent = new Intent(Home.this, Edit.class);
break;
case 1:
Intent intent1 = new Intent(Home.this, Edit.class);
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
答案 0 :(得分:0)
只是创建一个Intent不会移动到另一个Activity。您需要使用startActivity()
实际启动Intent ,如下所示:
switch (position) {
case 0:
Intent intent = new Intent(Home.this, Edit.class);
startActivity(intent);
break;
case 1:
Intent intent1 = new Intent(Home.this, Edit.class);
startActivity(intent1);
break;
default:
break;
}