findViewById in Fragment
In Fragment sub class in Android, you cannot directly use findViewById() to retrieve the control from view , similar with Activity. You need to do a single small step, this.getView(); Note that, to use this method, the view need to created, such as in onOptionsItemSelected
Code
txtTitle = (EditText)this.getView().findViewById(R.id.txt_title); |
If you wish to use it in OnCreateView, please do that in this way. At that moment, the view is not created yet, this.getView() will return null.
E.g.
Code
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_note_detail, container, false); | |
| |
txtTitle = (EditText) this.getActivity().findViewById(R.id.txt_title); |
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 3 feedbacks awaiting moderation...
Form is loading...