Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The constructor Intent is undefined error

I am using fragments. I have a spinner in the fragment. I want to lauch a new activity when spinner item is selected. I am getting this error

Error

The constructor Intent(UserHomeActivity, Class) is undefined 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;
        } 
    }); 
like image 432
vikas sharma Avatar asked Apr 10 '26 00:04

vikas sharma


1 Answers

Start new Activity as :

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

because Context is not super class of SherlockFragment class and you will need to use getActivity() which return Activity to current fragment is associated.

like image 164
ρяσѕρєя K Avatar answered Apr 11 '26 14:04

ρяσѕρєя K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!