Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android问题,自定义适配器中的数组值_Android_Android Arrayadapter_Android Mediaplayer - Fatal编程技术网

Android问题,自定义适配器中的数组值

Android问题,自定义适配器中的数组值,android,android-arrayadapter,android-mediaplayer,Android,Android Arrayadapter,Android Mediaplayer,我有一个通过自定义适配器填充的列表视图。适配器中的一切都正常工作,我评估是否获得视频、图像或音频文件,然后采取正确的操作 问题是,对于音频文件,它不能正常工作。我记录了音频文件名,它是正确的,但在处理onclick事件时,无论我单击哪个文件,它总是播放相同的文件。在onclick事件的日志中,它始终显示相同的内容,我无法理解为什么 谢谢你的帮助 适配器代码: notaV = resultp.get(MainActivity.AUDIO); //this gives me http://www.x

我有一个通过
自定义适配器填充的
列表视图
。适配器中的一切都正常工作,我评估是否获得视频、图像或音频文件,然后采取正确的操作

问题是,对于音频文件,它不能正常工作。我记录了音频文件名,它是正确的,但在处理onclick事件时,无论我单击哪个文件,它总是播放相同的文件。在onclick事件的日志中,它始终显示相同的内容,我无法理解为什么

谢谢你的帮助

适配器代码:

notaV = resultp.get(MainActivity.AUDIO); //this gives me http://www.xx.com/audio/file.amr
Log.e("audio adapter", notaV); //works good
Log.e("quien nota",resultp.get(MainActivity.QUIEN_ID));
reporte.append(" "+notaV); // I show the name of the file in a textview

//Then I load an drawable inside an imageview and set the listener
//to that image, when clicked look for play the audio
if (notaV.length() != 0) {
    imgs.setImageResource(R.drawable.playnote);

    imgs.setVisibility(View.VISIBLE);

    imgs.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent();  
            intent.setAction(android.content.Intent.ACTION_VIEW);
            //now here is when it always shows the same file over and over. 
            //I've tried with no final String or just using notaV
            //but with same result.
            final String audio = notaV;
            Log.e("voz",audio);
            //also the ID of the user that sent the audio it's being logged
            // as myself, while in previous Log it showed the correct ID.
            Log.e("quien click",resultp.get(MainActivity.QUIEN_ID));
            intent.setDataAndType(Uri.parse(audio), "audio/*");  
            context.startActivity(intent);
        }
    });
}

试着做这样的事情

  if (notaV.length() != 0) {
  imgs.setImageResource(R.drawable.playnote);

  imgs.setVisibility(View.VISIBLE);
  imgs.setTag(notaV);    
  imgs.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View view) {

        String audioUrl =  view.getTag.toString();
        Intent intent = new Intent();  
        intent.setAction(android.content.Intent.ACTION_VIEW);
        //now here is when it always shows the same file over and over. 
        //I've tried with no final String or just using notaV
        //but with same result.
        final String audio = audioUrl;
        Log.e("voz",audio);
        //also the ID of the user that sent the audio it's being logged
        // as myself, while in previous Log it showed the correct ID.
        Log.e("quien click",resultp.get(MainActivity.QUIEN_ID));
        intent.setDataAndType(Uri.parse(audio), "audio/*");  
        context.startActivity(intent);
    }
  });
}

您应该尝试添加音频文件的位置…谢谢,我在开始resultp=data.get(位置)上有这个;结果TP有自己的立场,也许你能给我一个更好的方法?再次感谢汉克斯的回答!你的意思是什么?结果获取(MainActivity.AUDIO)?我的错,它缺少了(),是getTag()而不是getTag是的,你是对的,它是
getTag()
而不是
getTag
谢谢!这就像一个魅力,这是一个简单但非常有效的解决方案。