in JQuery by
Q:
How can we get the context in a fragment  of Android?

► Click here to show 1 Answer

0 votes
by

You can use getActivity(), which returns the activity associated with a fragment. The activity is a context (since Activity extends Context).

You can also override the onAttach method of fragment:

public static class DummySectionFragment extends Fragment{
...
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        DBHelper = new DatabaseHelper(activity);
    }
}
Loan/Mortgage
Learn More with Madanswer

Related questions

0 votes
asked Jun 23, 2020 in JQuery by AdilsonLima
...