Hi I have an activity which holds a layout, the layout is divided into two linear layouts. The first layout has 4 buttons. The second one has fragments. Basically with each button press, a new fragment is displayed. All the fragments hold a layout . This layout has an edit text field, a button and a list view. Now everything is working fine, no errors till now. But the problem I am having is , when I try to create a database object and pass the context of the fragment class as parameter in the contructor, it simply shows an error. Here’s the code…Please have a look and guide me how can I solve the problem.
String text = null;
EditText enter_task;
// enter_task would be provided with its id, not a problem,
text = enter_task.getText().toString();
try{
// this is where te problem is
// normally I could pass the context of the activity within the constructr of database class as parameter. But since this class is a fragment, I am simply not able to do so.
myDatabase_today = new Database(MyFragment_today.this);
}
The solution which eclispe provides to the problem are:
1-> Change contructor Database(Context) to Database(MyFragment_today).
// here MyFragment_today is the fragment class’s name
2-> Create contructor Database(MyFragment_today).
Could anyone please solve this problem. I mean we can pass the activity’s context , but not the fragment class’s context, then how to proceede further.
Use getActivity() instead of the Fragment class name