public class fingerp extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_fingerp, container, false);
return rootView;
}
}
This id for tabbed view with buttons
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/documents");
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myDir.mkdirs();
EditText edit = (EditText)findViewById(R.id.editText);
String edt = edit.getText().toString();
File file = new File (myDir,edt);
}
this is for saving a folder in external storage in android and i am taking folder name input from user and to use that i am using this statement ↓
EditText edit = (EditText)findViewById(R.id.editText);
String edt = edit.getText().toString();
but findViewById is giving an error
Method findViewById()
is not implemented in class Fragment
. That method is implemented for Activity
or View
So, try the change below:
public void onCreate(Bundle savedInstanceState) {
....
EditText edit = (EditText) getActivity().findViewById(R.id.editText);
....
}
UPDATE
As well commented below, you can not rely on findViewById()
during onCreate
method to find Views from Parent Activity. This is also marked in the DOCS:
Note that this can be called while the fragment's activity is still in the process of being created. As such, you can not rely on things like the activity's content view hierarchy being initialized at this point. If you want to do work once the activity itself is created, see onActivityCreated(Bundle).
This way, if your EditText
is part of the R.layout.fragment_fingerp
You can do:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_fingerp, container, false);
EditText edit = (EditText) rootView.findViewById(R.id.editText);
String edt = edit.getText().toString();
File file = new File (myDir,edt);
return rootView;
}
Or just move your code from onCreate()
to onActivityCreated
:
public void onActivityCreated (Bundle savedInstanceState) {
...
EditText edit = (EditText) getActivity().findViewById(R.id.editText);
...
}