I have a listView in a fragment and I’m trying to use a switch statement to direct everyone to the rightful activity. Just can’t get it to work. I’ve been messing around with the code for about an hour, but I’m still getting the same error when creating an intent.
public class MenuFragment extends ListFragment {
String[] menu = { "Setting", "About" };
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, menu));
getListView().setCacheColorHint(0);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
switch (position) {
case 0:
Intent newActivity = new Intent(this, Settings.class);
startActivity(newActivity);
break;
case 1:
Intent newActivity1 = new Intent(this, About.class);
startActivity(newActivity1);
break;
}
}
}
Here are my errors:

You’re giving the Intent’s constructor a Fragment instance as the first parameter, where the current Activity should go.
Try this: