如何使用SherlockListFragment使用Intent启动新活动?

时间:2014-05-25 12:22:26

标签: android android-intent

我有一个带有sherlock列表片段的listfragment,如下所示:

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

但是在新的Intent中我得到这样的错误:构造函数意图未定义。我的代码怎么了?

1 个答案:

答案 0 :(得分:4)

试试这个

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

而不是

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