這裏已經提出了這個問題,但是我沒有解決我的問題。這裏是我的代碼如何在片段上實現後退按鈕按下設備
public class MyOrders extends Fragment {
View view;
private MyOrders.OnFragmentInteractionListener mListener;
FragmentManager fragmentManager;
Context context;
public MyOrders(){
}
public static MyOrders newInstance(String param1, String param2) {
MyOrders fragment = new MyOrders();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);;
context = getActivity();
fragment = new MyOrders();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.myorders, container, false);
fragmentManager = getFragmentManager();
}
// 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;
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
我通過新建 - >片段 - >空白片段
提出在Android Studio中該片段在設備背面底部的報刊,控制將轉向另一個片段(加載片段由下面的代碼)
public void loadFragment(Fragment fragment,String tag, FragmentManager fragmentManager){
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content, fragment);
fragmentTransaction.addToBackStack(tag);
fragmentTransaction.commit();
}
。 請幫我一把。我一整天都試過。
'Fragment'的BackPress就是這樣一個**錯誤的觀念**。 BackPress屬於容器活動。 –
你可以發佈代碼 – manjari
我想你可以搜索'android onbackpressed'。詢問代碼/教程是無關緊要的。 –