CannotFindSymbol CannotFindSymbol - 3 days ago 4
Android Question

Android Error using findViewById

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

Answer

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.

Comments