问题
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