Fragments
behave differently from Activities
. The view hierarchy in a fragment is created in onCreateView
which has to be overridden and returns the View
object. findByViewId()
is then called on the inflated view itself. See the documentation here
In onCreateView()
you inflate your view like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// your layout
View view = inflater.inflate(R.layout.dataedit, container, false);
// find the element in the inflated view
((EditText) view.findViewById(R.id.edSpecies)).requestFocus();
// get the context from the holding activity
DBAdapter msdb= new DBAdapter(getActivity().getApplicationContext(),"adfg", null);
...
return view;
}