3

我正在使用片段。我在片段中有一个微调器。我想在选择微调器项目时启动一个新活动。我收到此错误

错误

构造函数 Intent(UserHomeActivity, Class) 未定义 UserHomeActivity.java /SwipeyTabs/src/com/recscores/android 第 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;
        } 
    }); 
4

1 回答 1

10

启动新活动为:

Intent ii = new Intent(getActivity(),TeamHomeActivity.class);
 startActivity(ii); 

因为 Context 不是 SherlockFragment 类的超类,您需要使用 getActivity() 将 Activity 返回到当前片段关联。

于 2013-03-26T02:18:30.763 回答