无法解析方法'setOnItemClickListener(匿名com.app.app.adapters.ServerApater.OnItemClickListener)?

时间:2019-05-24 16:40:41

标签: java android

因此,我试图创建一个可以在外部播放器中播放当前流式视频的意图,但我对此setOnItemClickListener感到困惑,无法修复它。

这是我的代码:

public class DetailsActivity extends AppCompatActivity {

    public static ImageView imgBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        imgBack=findViewById(R.id.img_back);

        imgBack.setOnItemClickListener(new ServerApater.OnItemClickListener() {
            @Override
            public void onItemClick(View view, CommonModels obj, int position, ServerApater.OriginalViewHolder holder) {

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(obj.getStremURL()), "video/*");
                startActivity(Intent.createChooser(intent, "Complete action using"));
            }
        });


    }

而且请不要称它为几个类似问题的重复,因为我到处都是抬头,却找不到答案:(

1 个答案:

答案 0 :(得分:0)

您正在调用错误的侦听器,您需要使用 OnClickListener 代替 OnItemClickListener

imgBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(obj.getStremURL()), "video/*");
                startActivity(Intent.createChooser(intent, "Complete action using"));
            }
        });