开发者

Android: Creating a Function with a file path

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜