开发者

Android: Creating a Function with a file path

开发者 https://www.devze.com 2023-03-28 09:48 出处:网络
I\'m tryin开发者_C百科g to create a function that points to a sound file in my R.raw.xxxx folder. I can\'t figure out how to set the path to the file.

I'm tryin开发者_C百科g to create a function that points to a sound file in my R.raw.xxxx folder. I can't figure out how to set the path to the file.

public void setsounds(Button buttonname, int fileId) {

        buttonname.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                sound = (R.raw.fileID); //this is where R.raw.fileId should go
                return false;
            }
        });
}


R.raw.fileID is just an id and more precisely an integer. To get the actual resource, do something like that from your activity:

InoutStream is = getResources().openRawResource(R.raw.fileID);
0

精彩评论

暂无评论...
验证码 换一张
取 消