当我运行应用程序并尝试单击某个项目时,不要更改任何内容。它告诉我主要的活动,不能去第二。我已经导入了清单中的所有类。哪里错了?这是我的MainActivity
public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener {
Spinner spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner= (Spinner)findViewById(R.id.spinner);
ArrayAdapter adapter=ArrayAdapter.createFromResource(this, R.array.Alloggi, android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
final VideoView videoView = (VideoView)findViewById(R.id.videoView);
String urlpath = "android.resource://" + getPackageName()+ "/" + R.raw.videopol;
videoView.setVideoURI(Uri.parse(urlpath));
videoView.start();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
System.err.println("**************" + position);
switch (position) {
case 0:
Intent i = new Intent(getApplicationContext(), Casalini.class);
i.setClass(this, Casalini.class);
startActivity(i);
break;
case 1:
Intent ir = new Intent(getApplicationContext(),Bungalow.class);
ir.setClass(this, Bungalow.class);
startActivity(ir);
break;
case 2:
Intent ic = new Intent(getApplicationContext(),Villette.class);
ic.setClass(this, Villette.class);
startActivity(ic);
break;
case 3:
Intent it = new Intent(getApplicationContext(),Deluxe.class);
it.setClass(this,Deluxe.class);
case 4:
Intent iz = new Intent(getApplicationContext(),Camping.class);
iz.setClass(this, Camping.class);
}
Toast.makeText(parent.getContext(), parent.getItemAtPosition(position).toString() + " selected ", Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
这是我的第二项活动
` 公共课Casalini扩展了MainActivity {
ImageView im;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_casalini);
}
public void biggerView (View v) {
im=(ImageView) findViewById(R.id.selected);
switch (v.getId())
{
case R.id.image1:im.setImageResource(R.drawable.casalini);
break;
case R.id.image2:im.setImageResource(R.drawable.casalini1);
break;
case R.id.image3:im.setImageResource(R.drawable.casalini2);
break;
case R.id.image4:im.setImageResource(R.drawable.casalini3);
break;
case R.id.image5:im.setImageResource(R.drawable.casalini4);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
} `
答案 0 :(得分:0)
在这个函数中
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplicationContext(), secondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
finish();
startActivity(intent);
}
为您的借调活动添加意图