What are “tag” and “id” on Layouts?

后端 未结 3 561
执念已碎
执念已碎 2021-02-05 07:48

I know how the switch statement works but I don\'t know what this means (R.id.webbutton). Can anyone please explain what it is and also what is TAG? Is there any guide for the

3条回答
  •  清酒与你
    2021-02-05 08:12

    Start with the tutorials. (If you are so absolutely a beginner that you don't have a development environment set up yet, then start with Installing the SDK.)

    When you use the console log facility in Android, the first argument to the logging methods is a tag, which can be used to filter logcat output. A typical programming style is:

    public class Something { 
        private static final String TAG = "Something";
    
        public void aMethod() {
            Log.i(TAG, "Entered aMethod");
        }
        . . .
    }
    

    That's what TAG is.

    Resource IDs are explained in the tutorial. When you define a resource in XML, Android generates a class called R with nested classes for different kinds of resources (R.id, R.string, R.layout, etc.). Each of those nested classes has a constant for each resource of that type. R.id.webbutton might be generated from a layout file that has a button with attribute android:id="@+id/webbutton". This is all explained in the tutorials.

提交回复
热议问题