当我从我的微调器中选择一个选项时,我正在尝试启动一个新活动,但每当我选择启动新活动的选项时,应用程序崩溃。我正在以意图开始新活动,我正在使用onItemSelected作为微调器
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TextView;
public class Abs extends Activity {
private Spinner StretchType;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.abs);
addListenerOnSpinnerItemSelection();
tv = (TextView) findViewById(R.id.tvTypeofStretch);
}
public void addListenerOnSpinnerItemSelection() {
StretchType = (Spinner) findViewById(R.id.sSType);
StretchType
.setOnItemSelectedListener(new CustomOnItemSelectedListener());
}
public class CustomOnItemSelectedListener extends Activity implements
OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
// **************************** below here is where I start the new activity
switch (pos) {
case (1):
Intent i = new Intent(this, Practice.class);
startActivity(i);
break;
}
// **************************** above here is where I start the new activity
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
}
答案 0 :(得分:1)
使用classname.this
:
Intent i = new Intent(Abs.this, Practice.class);
Abs.this.startActivity(i);
答案 1 :(得分:0)
您应该使用以下内容替换startActivity(i)
-
Abs.this.startActivity(i);
此外,我发现您正在为Activity
课程延长SpinnerAdapter
。这需要吗?