I've a class MainActivity in which I'm implementing tabs+swipe navigation.
I'm creating different java files for the different fragnents. But the problem is I won't be able to access the values of the variables in MainActivity class.
Right now I've put the fragment class inside the MainActivity class and the app is working fine. How to accomplish the same result if want to create separate java file for separate fragments. This is my fagment class for now :
public static class fragmentLeft extends Fragment{
public fragmentLeft(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_left,
container, false);
View.OnClickListener mStartListener = new OnClickListener() {
public void onClick(View v) {
//mChronometer.start();
if (v.getId() == R.id.sign_in_button && !mPlusClient.isConnected()) {
Toast.makeText(getActivity(), "sadf", Toast.LENGTH_LONG).show();
if (mConnectionResult == null) {
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
// Try connecting again.
Toast.makeText(getActivity(),(CharSequence) e, Toast.LENGTH_LONG).show();
mConnectionResult = null;
mPlusClient.connect();
}
}
}
}
};
rootView.findViewById(R.id.sign_in_button).setOnClickListener(mStartListener);
return rootView;
}
}
These are the variables which are present in the MainActivity class that I want to access from the fragment class :
private static ProgressDialog mConnectionProgressDialog;
private static PlusClient mPlusClient;
private static ConnectionResult mConnectionResult;