I have defined a layout in an xml file in the ‘res’ folder of my android project. The ‘EditText’ element looks like:
<EditText android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numeric="integer|decimal"></EditText>
In my class file in my android project, I have the following:
public void doCalculation(View view) {
String firstNo = ((EditText) findViewById(R.id.editText1)).getText().toString();
String secondNo = ((EditText) findViewById(R.id.editText2)).getText().toString();
String operator = ((Spinner) findViewById(R.id.spinner1)).getSelectedItem().toString();
callWebService(firstNo, secondNo, operator );
}
Unfortunately, the first 2 assignments in my method above are showing an error in eclipse stating
EditText cannot be resolved to a type
I’ve no idea how to fix this. I’m using android 2.3.3 API 10.
Any help would be appreciated. Thanks
You need to import the
EditTextclass, so it’s known, using the following line at the beginning of your.javafile :Note that, in most cases, Eclipse can help you a lot : it has an Organize Imports feature, that will add the required
importlines :Source>Organize Imports