我有MainActivity,這是導航欄,以不同的片段不能轉換到片段listfragment
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();;
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction();
if (id == R.id.nav_camera) {
fragmentManager.beginTransaction().replace(R.id.container,fcafee).commit();
} else if (id == R.id.nav_gallery) {
fragmentManager.beginTransaction().replace(R.id.container.fclubs).commit();
} else if (id == R.id.nav_slideshow) { //erorr here
fragmentManager.beginTransaction().replace(R.id.container,feat).commit();
} else if (id == R.id.nav_manage) {
fragmentManager.beginTransaction().replace(R.id.container,fsnack).commit();
} else if (id == R.id.nav_share) {
fragmentManager.beginTransaction().replace(R.id.container,fsetting).commit();
}
而在我的片段fclubs我的ListView
public class FragmentClubs extends ListFragment {
我檢查所有的進口,但所有看起來不錯。
但我得到該行的錯誤消息,我有ListFragment
Error:(108, 71) error: incompatible types: FragmentClubs cannot be converted to Fragment
完全Fclubs:
public class FragmentClubs extends ListFragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
ListView listView;
String[] names;
final String LOG_TAG = "myLogs";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public FragmentClubs() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment FragmentClubs.
*/
// TODO: Rename and change types and number of parameters
public static FragmentClubs newInstance(String param1, String param2) {
FragmentClubs fragment = new FragmentClubs();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
// Here you can do something when items are selected/de-selected,
// such as update the title in the CAB
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.listView:
mode.finish(); // Action picked, so close the CAB
return true;
default:
return false;
}
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate the menu for the CAB
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.eatmenu, menu);
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// Here you can make any necessary updates to the activity when
// the CAB is removed. By default, selected items are deselected/unchecked.
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// Here you can perform updates to the CAB due to
// an invalidate() request
return false;
}
});
return inflater.inflate(R.layout.fragment_clubs,container,false); // TODO: Rename method, update argument and hook method into UI event
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
錯誤: Here what I get
發佈完整的'FragmentClubs'代碼和完整的'logcat' – Vucko
已經加入描述 –