When I attempt to start a Fragment from an Adapter, I get this exception.
I looked for similar issues, but casting to androidX is relatively new, so I couldn't find relevant solutions. I found a solution for passing a FragmentManager to the constructor when creating an Adapter object. This also required initilalizing a FragmentMAnager, and that's where I got stuck again.
The code for the process is:
AppCompatActivity activity = (AppCompatActivity) v.getContext();
int id = currentCountry.getId();
Fragment mdf = new DetailsFragment();
activity.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragments_container, mdf)
.addToBackStack(null)
.commit();
The exception message is
java.lang.ClassCastException: android.app.Application cannot be cast to androidx.appcompat.app.AppCompatActivity.
Any ideas for a solution? maybe the last option will be reverting back to android from androidX.
Is there other code that's needed to figure this issue out?