Comments (4)
Sure I can try to help you out. Share some code so i can see what you are doing.
from youtubeplaylist.
Hi again Sir,
It's your code with a very small modification:
package YoutubePackage;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.DecimalFormat;
import peyam.com.peyamtv.R;
/**
* Created by peyam on 2015-08-06.
*/
public class PersianMovies extends Fragment {
private static final String TAG = "YouTubeFragment";
public static String YOUTUBE_PLAYLIST;
private static final String PLAYLIST_KEY = "PLAYLIST_KEY";
private GridView mGridView;
private Playlist mPlaylist;
private PlaylistAdapter mAdapter;
private String[] videoId = null;
private int i = 0;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.youtube_videos, container, false);
mGridView = (GridView) root.findViewById(R.id.gvMovies1);
new GetYouTubePlaylistAsyncTask() {
@Override
public void onPostExecute(JSONObject result) {
if (result == null) return;
handlePlaylistResult(result);
}
}.execute(YOUTUBE_PLAYLIST, null);
return root;
}
private void initListAdapter(Playlist playlist) {
mAdapter = new PlaylistAdapter(playlist);
mGridView.setAdapter(mAdapter);
}
private void handlePlaylistResult(JSONObject result) {
try {
if (mPlaylist == null) {
mPlaylist = new Playlist(result);
initListAdapter(mPlaylist);
}
final Playlist.Page page = mPlaylist.addPage(result);
// fetch all the video details for the current page of Playlist Items
new GetYouTubeVideoAsyncTask() {
@Override
public void onPostExecute(JSONObject result) {
if (result == null) {
return;
}
try {
JSONArray resultItems = result.getJSONArray("items");
PlaylistItem playlistItem;
for (int i = 0; i < page.items.size(); i++) {
playlistItem = page.items.get(i);
playlistItem.video = new Video(resultItems.getJSONObject(i));
}
} catch (JSONException e) {
e.printStackTrace();
}
// make sure the UI gets updated
mAdapter.notifyDataSetChanged();
}
}.execute(page);
if (!mAdapter.setIsLoading(false)) {
mAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
protected class PlaylistAdapter extends BaseAdapter {
private final DecimalFormat formatter = new DecimalFormat("#,###,###");
private final LayoutInflater mInflater;
private Playlist mPlaylist;
private boolean mIsLoading = false;
PlaylistAdapter(Playlist playlist) {
mPlaylist = playlist;
mInflater = getLayoutInflater(null);
}
public boolean setIsLoading(boolean isLoading) {
if (mIsLoading != isLoading) {
mIsLoading = isLoading;
notifyDataSetChanged();
return true;
}
return false;
}
@Override
public int getCount() {
return mPlaylist.getCount() + (mIsLoading ? 1 : 0);
}
@Override
public PlaylistItem getItem(int i) {
return mPlaylist.getItem(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
if (mIsLoading && position == (getCount() - 1)) {
return mInflater.inflate(R.layout.youtube_movies_loading, null, false);
}
ViewHolder viewHolder;
if (convertView == null || convertView.getTag() == null) {
viewHolder = new ViewHolder();
convertView = mInflater.inflate(R.layout.custom_row_movies, null, false);
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
viewHolder.thumbnail = (ImageView) convertView.findViewById(R.id.ivThumb);
viewHolder.duration = (TextView) convertView.findViewById(R.id.duration);
viewHolder.viewCount = (TextView) convertView.findViewById(R.id.view);
convertView.setTag(viewHolder);
}
viewHolder = (ViewHolder) convertView.getTag();
final PlaylistItem item = getItem(position);
if (item.title.length() >= 20) {
viewHolder.title.setText(item.title.substring(0, 21));
} else {
viewHolder.title.setText(item.title);
}
// Loading Image
Picasso.with(getActivity())
.load(item.thumbnailUrl)
.into(viewHolder.thumbnail);
// set the click listener to play the video
viewHolder.thumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + item.videoId)));
}
});
// create and set the click listener for both the share icon and share text
// View.OnClickListener shareClickListener = new View.OnClickListener() {
// @Override
// public void onClick(View view) {
//
//
// Intent sendIntent = new Intent();
// sendIntent.setAction(Intent.ACTION_SEND);
// sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Watch \"" + item.title + "\" on YouTube");
// sendIntent.putExtra(Intent.EXTRA_TEXT, "http://www.youtube.com/watch?v=" + item.videoId);
// sendIntent.setType("text/plain");
// startActivity(sendIntent);
// }
// };
if (item.video != null) {
// set the video duration text
viewHolder.duration.setText(item.video.duration);
// set the video statistics
viewHolder.viewCount.setText(formatter.format(item.video.viewCount));
}
// get the next playlist page if we're at the end of the current page and we have another page to get
final String nextPageToken = mPlaylist.getNextPageToken(position);
if (!isEmpty(nextPageToken) && position == getCount() - 1) {
new GetYouTubePlaylistAsyncTask() {
@Override
public void onPostExecute(JSONObject result) {
handlePlaylistResult(result);
}
}.execute(YOUTUBE_PLAYLIST, nextPageToken);
setIsLoading(true);
}
return convertView;
}
private boolean isEmpty(String s) {
if (s == null || s.length() == 0) {
return true;
}
return false;
}
class ViewHolder {
ImageView thumbnail;
TextView title;
TextView duration;
TextView viewCount;
}
}
}
from youtubeplaylist.
If I understand your question right, you want the click listener to be on the entire cell in your grid view. In which case you should be able to the click listener on the convertView object
convertView = mInflater.inflate(R.layout.custom_row_movies, null, false);
// set the click listener to play the video
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + item.videoId)));
}
});
from youtubeplaylist.
Take a look at the most recent version of the code. I've updated it with usage of the RecyclerView. You can easily modify it to show a grid view.
from youtubeplaylist.
Related Issues (20)
- Weird behaviour when refresh/load another data on RecyclerView HOT 5
- java.lang.NullPointerException HOT 5
- Playlist Not Showing HOT 1
- java.lang.NullPointerException HOT 1
- Openin video inside app HOT 3
- Colored indicator on top left corner on thumbnail HOT 1
- channel support ? HOT 2
- Get only last video of playlist HOT 2
- How do I get a list of videos that I came from last to first? HOT 2
- How to put the playlist options inside the Navigation Drawer like this in the spinner HOT 3
- The Green/Blue thing in corner? HOT 3
- How to put a ProgressBar in uploading videos? HOT 1
- How can we implement Search Functionality in the Playlist
- Get Channel Name as Well HOT 1
- PlalistThumbnail gives null HOT 1
- Black borders on thumbnails HOT 1
- How to add comment in android app. HOT 1
- All flavors must now belong to a named flavor dimension HOT 1
- On production playstore HOT 4
- Getting run-time error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from youtubeplaylist.