A very simple example of buttons in Android?

I want a very simple button with some explanation / vizual thing, maybe oncreate / onlauncher to do something that makes you smile! I have tried the button here, but the error is here. If someone can guide me to find a ready-made example of Android buttons, it may be the simplest. History shows the problems of R and XML files. If someone can clearly explain how to do this, it may be the simplest: a very simple button. Its directory tree, etc?

Please provide a simple example of buttons in Android, nothing else

resolvent:

First, let's take a look at your test. Java, which won't work properly. I hope you understand the basic concepts of object-oriented programming and get rid of static methods

In Android, there is a class called activity. You need to extend it. If you follow lazy Ninja's answer, the eclipse plugin may have created one for you (it may be called mainactivity. Java). In short, activities represent views in your application. In your simple example, most (if not all), your code will go to this class

In Android, instead of using public static void main (string [] args), you override the oncreate method of activity. In androidmanifest.xml, you define your activity (you only need one at this time) and the activity started when the application starts. Its oncreate is the starting point of the whole application (check the structure created by eclipse again)

In oncreate, you should call setcontentview with the layout you want to use in the activity. The layout is provided to setcontentview as an integer parameter in the generated r class, such as r.layout.layout_ file_ Name, which maps to RES / layout / layout_ file_ XML file in name.xml

A layout file is a file that contains the required layout declaration. In your case, it may have a LinearLayout as the root element and two buttons

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>