Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

android - Getting an "Unresolved reference" error for an editText id in main activity

I have just started Android Development with a basic app which takes the username and display in Toast but came across an error in the main activity. It says "Unresolved references: editName". I tried making the app again, manually importing editText widget and changing the id name but nothing works. It would be great if someone can tell me what's going wrong. ScreenShot of the code with error underlined with red..... Module build.... Project build


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'll show you the example in Java.

You must create a variable in your activity class

EditText editName;

then you must override the onCreate() method of the Activity class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    editName = (EditText) findViewById(R.id.editName);
}

overriding the onCreate() you can take a reference to your EditText.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...