Reputation: 2810
I am new to this android application development. I am trying to find textfield using findViewById Eclipse keep asking me to create a new method for findViewById. Here is my code.
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle SavedInstanceState) {
return inflater.inflate(R.layout.myFragment, container,false);
//find textarea
TextView textArea = (TextView) findViewById(R.id.txtField_curDateTime);
}
Please note i have myFragment.java and myFragment.xml files.
Appreciate your help. Thanks
Upvotes: 1
Views: 82
Reputation: 6166
Try this:
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle SavedInstanceState) {
View vObject = inflater.inflate(R.layout.myFragment, container,false);
//find textarea
TextView textArea = (TextView)vObject.findViewById(R.id.txtField_curDateTime);
return vObject;
}
Upvotes: 1
Reputation: 68177
Do it like this:
View v = inflater.inflate(R.layout.myFragment, container,false);
TextView textArea = (TextView) v.findViewById(R.id.txtField_curDateTime);
return v;
Moreover, define TextView textArea
outside the onCreateView
so that its available to other methods too.
Upvotes: 3