开发者

A Java question, but an Android question, here's why:

The only available reproducible example I can find to share with the board is the Android sample code NotePad, which is loaded into the IDE's Package Explorer as 'NotesList'.

I want to know why, in the package's NoteEditor.java, LinedEditText (extended from EditText) can't be renamed? In other words why can't I rewrite this extended class as, say, "Lined_EditText" in the two lines where the word exists, in its class name and its constructor? They are the only two locations, as far as I can determine, where the words exist in the entire package.

(There is an org.hermit.android.widgets.LinedEditText at http://moonblink.googlecode.com/svn/trunk/HermitAndroid/doc/org/hermit/android/widgets/LinedEditText.html, but this NotePad sample in the Android SDK doesn't import that clas开发者_JAVA技巧s. The sample only imports android.widget.EditText .)

Thanks for any help.


That class is referenced from the layout file that describes the UI -- http://developer.android.com/resources/samples/NotePad/res/layout/note_editor.html

If you change the name of the Java class without the name the layout file uses, the layout will fail during inflation. You should see in the log an explicit error message about the inflate failing, it being unable to find the LinedEditText class, and what line this happened in.

The NotePad sample doesn't import the LinedEditText class you reference because... well, it is implementing its own LinedEditText right on the code. In fact the source you reference was probably just copied from the NotePad sample.


I don't have the example in front of me to confirm, but if this is the main class in the file, it has to match the file name.

Thus you can rename it to Lined_EditText if the filename is also renamed to Lined_EditText.java.

If you are using Eclipse (or any decent IDE), it should take care of this for you with the refactor option in the context menu.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜