In android, I'm not sure I quite understand the R
class. I'm going through the sudoku example, and I have this snippet of code:
switch (v.getId()) // the id of the argument passed is evaluated by switch statement { case R.id.about_button: // Intent i = new Intent(this, about.class); startActivity(i); break; // More buttons go here (if any) ... }
I'm brand new to Java, but from what I gather it looks like it's taking input (the touch screen being touched on the button) and evaluating the argument. Then the case statement is setup if the about button is recognized, and a new interface screen is created and then navigated to on the phone.
Is this right?
If I got the gist of that correct, why is the deal with the "R" class?
Why is it called to recognize the ID of the button?
I thought the super class (in this project) was the SudokuActivity class.
R class is generated by Android tools from your resources before compiling your code. It contains assigned numeric constant for each resource that you can refer in your project. For example, you have XML resource file that contains about_button .
R is the class that contains all the resource ids for your application.
R is a class containing the definitions for all resources of a particular application package. It is in the namespace of the application package. For example, if you say in your manifest your package name is com. foo. bar , an R class is generated with the symbols of all your resources in com.
Android R. java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. If you create any component in the activity_main. xml file, id for the corresponding component is automatically created in this file.
R.java
is the dynamically generated class, created during build process to dynamically identify all assets (from strings to android widgets to layouts), for usage in java classes in Android app. Note this R.java
is Android specific (though you may be able to duplicate it for other platforms, its very convenient), so it doesn't have much to do with Java language constructs. Take a look here, for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With