理解Android中的R类 [英] Understand the R class in Android

查看:45
本文介绍了理解Android中的R类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 android 中,我不确定我是否完全理解 R 类.我正在查看数独示例,我有以下代码片段:

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) ...
}

我是 Java 的新手,但从我收集的信息来看,它看起来像是在接受输入(触摸屏上的按钮)并评估参数.如果识别出关于按钮,则设置 case 语句,并创建一个新的界面屏幕,然后导航到手机上.

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.

这样对吗?

如果我的要点是正确的,为什么要处理R"类?

If I got the gist of that correct, why is the deal with the "R" class?

为什么会调用识别按钮的ID?

Why is it called to recognize the ID of the button?

我认为超类(在这个项目中)是 SudokuActivity 类.

I thought the super class (in this project) was the SudokuActivity class.

推荐答案

R.java 是动态生成的类,在构建过程中创建以动态识别所有资产(从字符串到 Android 小部件再到布局)),用于 Android 应用程序中的 Java 类.请注意,此 R.java 是 Android 特定的(尽管您可以将其复制到其他平台,但非常方便),因此它与 Java 语言结构没有太大关系.查看此处,了解更多详情.

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.

这篇关于理解Android中的R类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆