gpt4 book ai didi

android - 构造函数 Intent 未定义错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:51:03 24 4
gpt4 key购买 nike

我正在使用 fragment 。我在 fragment 中有一个微调器。选择微调项后,我想发起一项新 Activity 。我收到这个错误

错误

构造函数 Intent(UserHomeActivity, Class) 未定义 UserHomeActivity.java/SwipeyTabs/src/com/recscores/android line 28 Java Problem

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;
}
});

最佳答案

开始新 Activity 为:

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

因为 Context 不是 SherlockFragment 类的父类(super class),您将需要使用 getActivity() 返回与当前 fragment 关联的 Activity。

关于android - 构造函数 Intent 未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com