Cannot Click item in a ListView to show YouTube Video

痴心易碎 提交于 2019-12-08 07:44:57

问题


I've used the following example to build a listview with an onClick listener which should launch YouTube when a thumbnail is clicked. However the youtube application does not launch onClick.

public class Home extends YouTubeBaseActivity implements

VideoClickListener {

    private VideosListView listView;

    public static final String API_KEY = "AIzaSyC0Te2pyooXzuyLaE6_SsFlITKCwjj55fI";
    public static final String VIDEO_ID = "o7VVHhK9zf0";
    String PLAYLIST = "vevo";
    Activity activity;
    int imageArray[];
    String[] stringArray;

    private OnPageChangeListener mPageChangeListener;
    ImagePagerAdapter adapter = new ImagePagerAdapter();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        ...


        listView = (VideosListView) findViewById(R.id.videosListView);
        listView.setOnVideoClickListener(this);
        new GetYouTubeUserVideosTask(responseHandler, PLAYLIST).execute();
    }

    Handler responseHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            populateListWithVideos(msg);
        };
    };

    private void populateListWithVideos(Message msg) {
        Library lib = (Library) msg.getData().get(
                GetYouTubeUserVideosTask.LIBRARY);
        listView.setVideos(lib.getVideos());
    }

    @Override
    protected void onStop() {
        responseHandler = null;
        super.onStop();
    }

    @Override
    public void onVideoClicked(Video video) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(video.getUrl()));
        startActivity(intent);
    }

P.S.

This issue is REALLY stumping me. If anyone would like to take a closer look I've uploaded the entire project here:

https://www.dropbox.com/s/irab3x18nhj4twt/idg.zip

Tutorial Source:

http://blog.blundell-apps.com/click-item-in-a-listview-to-show-youtube-video/

来源:https://stackoverflow.com/questions/20476070/cannot-click-item-in-a-listview-to-show-youtube-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!