开发者

Newbie Android issue

I have just started with Android with the usual Hello World project template in Eclipse. I modified the layout XML and removed the label that says "Hello World, !", and added a couple of other controls. However, these are not reflected in the app, within the emulator. When I run this app from Eclipse again it is开发者_如何学运维 still showing the Hello World label!

I'm sure it's something terribly simple that I have completely missed. Can someone please point me in the right direction?

Many thanks, Dany.


Try the following fixes in roughly the order I'm prescribing.

  • Make sure you saved the layout. If it wasn't saved, that would certainly do it.

  • Take a look at the xml itself, click on the small xml tab placed at the bottom of your layout. If you want to make the xml more easily readable, press Ctrl-Shift f if you're on windows. Does it look like what you'd expect?

  • For the controls, start by placing a linear layout, and make sure that the controls are placed within the linear layout. To make sure the controls are properly nested, use the Outline View, or better yet, just edit the xml file itself.

  • Clean your code (this deletes the generated files and rebuilds the project). In Eclipse, it's under the Project > Clean... (I think)

  • Make sure all the other projects are closed so that they do not interfere with the current project you might be working on. For all I know, you might be compiling the wrong one.

  • When you say you removed the label, did you click inside the textlabel and just change the wording? If so, that only changed the id/name of the label not the string inside the label. To change the string inside the textlabel, use the Properties View to do that.

  • To make sure you're looking at the right instance of the emulator. Close your emulator before running the project again (this is not normally advised for speed reasons, but in this case, I just want to check that the new emulator is even launching correctly). And by the way, when you say emulator, I hope that you're not confusing it with the what-you-see-is-what-you-get editor.

  • If that still doesn't work, go to the gen folder (generated files). Open the R.java file. Click inside, add a line return. And rebuild your project. I know this one sounds like a weird fix, but this fix does work from time to time.

  • Also, take a look at the Problems View, does it list a problem? And look at the Console when you're rerunning the code. What does the Console say?

Hope this helped. If this still doesn't work, I can always suggest more ways to debug your app.


Beginning Android Development


http://www.vogella.de/articles/Android/article.html

  • Checkout Sections 2.4 and 3.6 of the Tutorial

NOTE: In case U haven't downloaded it yet, get the SDK here:

http://developer.android.com/sdk/index.html

GoodLUCK!!


Edit your question and show us your XML file - you probably forgot to change the line android:text="@string/hello" but I'd be able to tell you for sure if I saw the file. Alternatively, you might not have changed the value for the string "hello" - to do that, go to "values" folder in the project directory, then edit strings.xml.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜