I have a base class fragment (as shown below). I extend this class in 3 other fragment classes, each of which share the same EditText
that needs to be accessed in these 3 fragments. For this reason, I have the EditText
variable set up in the base class (so I don't have to call it 3 times, once in each fragment).
Should this variable be public
or should it be private
with a getter method set up? Why?
Here is my base class fragment:
public abstract class BaseFragment extends Fragment {
public EditText editText;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(getFragmentLayout(), container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
editText = (EditText) view.findViewById(R.id.editText);
}
protected abstract int getFragmentLayout();
}