2017-06-21 59 views
-1

在我的項目中,我添加了按鈕或可點擊的圖像按鈕。然而,我不知道爲什麼我在.id.example之前使用'R'。我在網上查詢過,但沒有任何信息能給我一個明確的答案。誰能解釋一下?'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(); 
     } 
    }); 
+2

「R」代表「資源」。你應該用Google搜索它。 –

回答

0

R.java是動態生成的類,在生成過程中產生動態識別所有資產(從字符串到機器人部件來佈局),用於使用在Java類在Android應用程序。

看一看here,瞭解更多詳情。