I am using tabbed activity. I have used a button in the first tab for which on button click it should to the second tab.
How can I use Intent to call Second Fragment from First Fragment?
Here is the code of my both fragments.
First Fragment:
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");
}
}
Second Fragment:
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");
}
}
The code which I am using now shows the following error on clicking the first button:
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)
anyone provide me a solution to get through this.Thanks..