What I have in mind is to use two fragments, first one to show the contacts list and second one to show the details of contact which is being selected in the upper fragment.
The class that I'm using to extend the Fragment class does not allow me to use getContentResolver()
method due to the context issue. Now I'm trying to fetch the contact in the same class which is extending Fragment class and use it to show in the list view and its details. After going through some older solution I found the way to create a function and pass Context to it as a parameter but the problem is I don't have to call it from any other class which is extending Activity. I want to do it from that same class extending Fragment.
How should I do this?
Any help will be highly appreciated.
Try to add this code to a previous activity:
// a static variable to get a reference of our application context
public static Context contextOfApplication;
public static Context getContextOfApplication()
{
return contextOfApplication;
}
and in the same activity, in your onCreate method add this line:
contextOfApplication = getApplicationContext();
In your fragment you can access this by using :
Context applicationContext = YourActivity.getContextOfApplication();
applicationContext.getContentResolver();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With