タブ付きアクティビティを使用しています。最初のタブのボタンをクリックして、それを2番目のタブに移動する必要があります。インテントを実装して別のフラグメントからフラグメントを呼び出す方法
インテントを使用してファーストフラグメントから2番目のフラグメントを呼び出すにはどうすればよいですか?
ここに私の両方の断片のコードです。
最初のフラグメント:
package com.touchsmart.spectacular.ui.Fragments;
import....
public class ShippingFragment extends Fragment {
private LinearLayout addnew;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//returning our layout file
View view = inflater.inflate(R.layout.fragment_shipping, container, false);
addnew = (LinearLayout) view.findViewById(R.id.addnew);
addnew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(),PaymentFragment.class);
startActivity(i);
}
});
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//you can set the title for your toolbar here for different fragments different titles
getActivity().setTitle("Check Out");
}
}
第2のフラグメント:
package com.touchsmart.spectacular.ui.Fragments;
import...
public class PaymentFragment extends Fragment{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//returning our layout file
View view = inflater.inflate(R.layout.fragment_payment, container, false);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//you can set the title for your toolbar here for different fragments different titles
getActivity().setTitle("Check Out");
}
}
私が今使っているコードは、最初のボタンをクリックで次のエラーを示しています
FATAL EXCEPTION: main Process: com.touchsmart.spectacular, PID: 18942
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.touchsmart.spectacular/com.touchsmart.spectacular.ui.Fragments.PaymentFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
at android.app.Activity.startActivityForResult(Activity.java:4225)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.support.v4.app.ActivityCompatJB.startActivityForResult(ActivityCompatJB.java:30)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:146)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:932)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:1047)
at android.support.v4.app.Fragment.startActivity(Fragment.java:944)
at android.support.v4.app.Fragment.startActivity(Fragment.java:933)
at com.touchsmart.spectacular.ui.Fragments.ShippingFragment$1.onClick(ShippingFragment.java:36)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
誰もが提供私はこれを克服するための解決策です。ありがとう..
は 'PaymentFragment'は'は 'FragmentManager' –
は、このリンクに行く'使用ShippingFragment'でそれを置き換える必要がありFragment' [https://stackoverflow.com/a/25945639/7226732] – Mohammad