Where can I find the source code for classes like AppCompatActivity or functions like setContentView() in Android Studio?

Asked 2 years ago, Updated 2 years ago, 57 views

I can see the explanations with ctrl+q, but I wonder where the source is and where the file is imported.

And,

If I make a button called "Button1" in activity_main.xml,

Allows coding of button1.setOnClickListener.

But if you look at it here, it looks like "Button1" has become an instance of a class, where is the source code for this process? I wonder if you have one.

android-studio

2022-09-20 21:38

1 Answers

Because the build is managed by the gradient, the actual source you refer to is the cache file generated by the gradient.

You can move the class and method to the definition by ctrl+[click].

After moving, you can see that the internal java file of the jar file is displayed in the top window.

AppCompatActivity.I followed java and actually checked it, and it was pointing to the file below.

C:\Users\emfpr\.gradle\caches\modules-2\files-2.1\androidx.appcompat\appcompat\1.1.0\9865019bbd2d95e41dede3d8ebf964aa93f97766\appcompat-1.1.0-sources.jar

The above file is for header purposes only, and the actual method is provided by the compiled internal core library.

If you create a button with the id "button1" in activity_main.xml, it will not be created until you parse the xml at runtime and create an instance because you only have the specification.

The creation process cannot be verified because it refers to a compiled internal core library.

Therefore, Android is designed to be implemented by importing objects based on pre-registered id rather than a predefined class, converting them to suit the type, and using them.

Button button1 = (Button) findViewById(R.id.button1) ;
button1.setOnClickListener(...);

For more information, please search by findViewById and resource side for more information.

Thank you.


2022-09-20 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.