简体   繁体   中英

How To Start New Activity with Intent Using SherlockListFragment?

I have a listfragment with sherlock list fragment like this :

public class FragmentTab1 extends SherlockListFragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragmenttab1, null);
    setListAdapter(new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, DaerahWisata.pantai));
    return view;
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    Intent a;
    switch (position) {

    case 0:
        a = new Intent(FragmentTab1.this, Maps.class); //error
        break;
        if (null != a)
            startActivity(a);
    }
}

But in new Intent i get error like this : The constructor intent is undefined. Whats wrong with my code?

Try this

  a = new Intent(getActivity(), Maps.class); 

instead of

  a = new Intent(FragmentTab1.this, Maps.class); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM