我正在使用片段。我在片段中有一个微调器。我想在选择微调器项目时进行新的活动。我收到此错误
错误
构造函数Intent(UserHomeActivity,Class)未定义UserHomeActivity.java / SwipeyTabs / src / com / recscores / android line 28 Java问题
public class UserHomeActivity extends SherlockFragment{
Spinner spinnerTeam;
Spinner spinnerLeague;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view =inflater.inflate(R.layout.user_home, container, false);
// Team Spinner
spinnerTeam = (Spinner)view.findViewById(R.id.spinner_team);
spinnerTeam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
**Intent ii = new Intent(UserHomeActivity.this,TeamHomeActivity.class);
startActivity(ii); **
}
public void onNothingSelected(AdapterView<?> adapterView) {
return;
}
});
答案 0 :(得分:10)
以...开始新活动:
Intent ii = new Intent(getActivity(),TeamHomeActivity.class);
startActivity(ii);
因为Context不是SherlockFragment类的超类,你需要使用getActivity()将当前片段的Activity返回关联。