View ID and resourceID

view ID

For each widget in the layout, we set a ID. This ID can be retrieved in the java file as follows

//this is a unique number generated by system
    int id = view.getId();

    // the id we set
    String ourId =  view.getResources().getResourceEntryName(id);

Resource ID

The files we place under res get a system generated ID as well. This can be got by R.raw.filename, which is an integer. But in some cases (appPhrease eg), we may need to get this ID from file name in java file,

//getting resource id (R.id.name) from file name
        int resourceId = getResources().getIdentifier(ourId,"raw",getPackageName());

        MediaPlayer mPlayer = MediaPlayer.create(this,resourceId);

Example project:

App phrase