'R' 的目的是什么?
What is the purpose of 'R'?
在我的整个项目中,我添加了按钮或可点击的图像按钮。但是我不知道为什么我在 .id.example 之前使用 'R'。我在网上查询过,但没有什么能给我一个明确的答案。谁能解释一下?
private Button DisplayRoutineButton;
private Button ClearRoutineButton;
private static int ImageID = 0;
ImageView activityslotlocationa, activityslotlocationb, activityslotlocationc, activityslotlocationd, activityslotlocatione, activityslotlocationf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.routineeditscreen);
myDb = new Database(this);
DisplayRoutineButton = (Button) findViewById(R.id.displayroutinebutton);
ClearRoutineButton = (Button) findViewById(R.id.clearroutinebutton);
// Display Routine Button
DisplayRoutineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("BUTTON CLICKED", "Display Schedule");
Intent i = new Intent(MondayRoutineEdit.this, MondayRoutineDisplay.class);
Log.d("SUCCESSFUL", "Loading Monday Routine Display");
startActivity(i);
}
});
// Delete Routine Button
ClearRoutineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("BUTTON CLICKED", "Delete Routine");
deleteRoutine();
Log.d("SUCCESSFUL", "Routine Deleted");
}
});
// Audio Feedback
ImageView artactivity = (ImageView) this.findViewById(R.id.artactivityimage);
final MediaPlayer artsoundeffect = MediaPlayer.create(this, R.raw.art);
artactivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
artsoundeffect.start();
}
});
ImageView bedtimestoryactivity = (ImageView) this.findViewById(R.id.bedtimestoryactivityimage);
final MediaPlayer bedtimestorysoundeffect = MediaPlayer.create(this, R.raw.bedtimestory);
bedtimestoryactivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bedtimestorysoundeffect.start();
}
});
R.java 是动态生成的 class,在构建过程中创建以动态识别所有资产(从字符串到 android 小部件再到布局),用于 java classes 在 Android 应用程序中。
查看here了解更多详情。
在我的整个项目中,我添加了按钮或可点击的图像按钮。但是我不知道为什么我在 .id.example 之前使用 'R'。我在网上查询过,但没有什么能给我一个明确的答案。谁能解释一下?
private Button DisplayRoutineButton;
private Button ClearRoutineButton;
private static int ImageID = 0;
ImageView activityslotlocationa, activityslotlocationb, activityslotlocationc, activityslotlocationd, activityslotlocatione, activityslotlocationf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.routineeditscreen);
myDb = new Database(this);
DisplayRoutineButton = (Button) findViewById(R.id.displayroutinebutton);
ClearRoutineButton = (Button) findViewById(R.id.clearroutinebutton);
// Display Routine Button
DisplayRoutineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("BUTTON CLICKED", "Display Schedule");
Intent i = new Intent(MondayRoutineEdit.this, MondayRoutineDisplay.class);
Log.d("SUCCESSFUL", "Loading Monday Routine Display");
startActivity(i);
}
});
// Delete Routine Button
ClearRoutineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("BUTTON CLICKED", "Delete Routine");
deleteRoutine();
Log.d("SUCCESSFUL", "Routine Deleted");
}
});
// Audio Feedback
ImageView artactivity = (ImageView) this.findViewById(R.id.artactivityimage);
final MediaPlayer artsoundeffect = MediaPlayer.create(this, R.raw.art);
artactivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
artsoundeffect.start();
}
});
ImageView bedtimestoryactivity = (ImageView) this.findViewById(R.id.bedtimestoryactivityimage);
final MediaPlayer bedtimestorysoundeffect = MediaPlayer.create(this, R.raw.bedtimestory);
bedtimestoryactivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bedtimestorysoundeffect.start();
}
});
R.java 是动态生成的 class,在构建过程中创建以动态识别所有资产(从字符串到 android 小部件再到布局),用于 java classes 在 Android 应用程序中。
查看here了解更多详情。