在我的项目中,我添加了按钮或可点击的图像按钮。但是我不知道我为什么要使用' R'在.id.example之前。我在网上查询但没有什么可以给我一个明确的答案。谁能解释一下?
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();
}
});
答案 0 :(得分:0)
R.java是动态生成的类,在构建过程中创建,用于动态识别所有资产(从字符串到android小部件到布局),用于Android应用程序中的java类。
请查看here,了解详情。