I'm trying to make a gridview that shows images and So it shows the gridview but no images, if clicked it boxes the gridview pops out the link. i got no idea why my images is missing on the gridview...
heres my fragment class
public class FragmentD extends Fragment {
public FragmentD(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_d, container, false);
try {
EditText main_searchField = (EditText) rootView.findViewById(R.id.editText_search_d);
String main_search = main_searchField.getText().toString();
Spinner main_categoryField = (Spinner) rootView.findViewById(R.id.spinner_d);
String category = main_categoryField.getSelectedItem().toString();
GridView main_gridviewField = (GridView) rootView.findViewById(R.id.gridView_main);
main_gridviewField.setAdapter(new MyGridViewAdapter(getActivity()));
main_gridviewField.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3) {
Toast.makeText(getActivity(), MyGridViewConfig.getResim_list().
get(position), Toast.LENGTH_SHORT).show();
}
});
if(main_gridviewField.isActivated()){
ImageView sad_face = (ImageView)getActivity().findViewById(R.id.imageView_main_sadface);
sad_face.setVisibility(View.INVISIBLE);
TextView nosuchdata = (TextView)getActivity().findViewById(R.id.textView_main_nodatafound);
nosuchdata.setVisibility(View.INVISIBLE);
}
} catch (Exception e){
Toast.makeText(getActivity(), "EPIC FAIL", Toast.LENGTH_LONG).show();
}
//new search_mainActivity(getActivity()).execute(main_search, category);
return rootView;
}
}
heres my adapter
public class MyGridViewAdapter extends BaseAdapter implements ListAdapter {
private Context context;
public MyGridViewAdapter(Context context) {
super();
this.context = context;
MyGridViewConfig.addImageUrls();
}
public int getCount() {
return MyGridViewConfig.getResim_list().size();
}
public Object getItem(int position) {
return MyGridViewConfig.getResim_list().get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView==null)
{
imageView=new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(100,100));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(5,5,5,5);
}else{
imageView=(ImageView)convertView;
}
imageView.setImageDrawable(LoadImageFromURL(MyGridViewConfig.
getResim_list().get(position)));
return imageView;
}
private Drawable LoadImageFromURL(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src");
return d;
}catch (Exception e) {
System.out.println(e);
return null;
}
}
}
heres my config java
public class MyGridViewConfig {
private static ArrayList<String> resim_list=new ArrayList<String>();
public static ArrayList<String> getResim_list() {
return resim_list;
}
public static void setResim_list(ArrayList<String> resim_list) {
MyGridViewConfig.resim_list = resim_list;
}
public static void addImageUrls(){
// Here you have to specify your image url path
resim_list.add("http://fc08.deviantart.net/fs71/f/2010/319/d/6/neko_chibi__s_by_alykun17-d32y2v5.jpg");
resim_list.add("http://fc08.deviantart.net/fs71/f/2010/319/d/6/neko_chibi__s_by_alykun17-d32y2v5.jpg");
resim_list.add("http://fc08.deviantart.net/fs71/f/2010/319/d/6/neko_chibi__s_by_alykun17-d32y2v5.jpg");
resim_list.add("http://fc08.deviantart.net/fs71/f/2010/319/d/6/neko_chibi__s_by_alykun17-d32y2v5.jpg");
resim_list.add("http://fc08.deviantart.net/fs71/f/2010/319/d/6/neko_chibi__s_by_alykun17-d32y2v5.jpg");
resim_list.add("http://fc08.deviantart.net/fs71/f/2010/319/d/6/neko_chibi__s_by_alykun17-d32y2v5.jpg");
}
}
You can't download the images on your main UI thread, so do it in an AsyncTask. Create this class:
class LoadImageTask extends AsyncTask<String, Void, Drawable > {
public LoadImageTask(ImageView iv)
{
imageView = iv;
}
ImageView imageView;
protected Drawable doInBackground(String... urls) {
try {
URLConnection connection = new URL(urls[0]).openConnection();
connection.connect();
InputStream is = (InputStream) connection.getContent();
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (Exception e) {
// e.printStackTrace();
return null;
}
}
protected void onPostExecute(Drawable drawable) {
if(drawable != null)
imageView.setImageDrawable(drawable);
}
}
Then change your getView() function to use the AsyncTask instead of LoadImageFromURL:
// imageView.setImageDrawable(LoadImageFromURL(MyGridViewConfig.
// getResim_list().get(position)));
new LoadImageTask(imageView).execute(MyGridViewConfig.getResim_list().get(position));
are you set android.permission.INTERNET permission?
Related
How to Display the Local image(drawable image file) to cardview via json. I want to load image in offline rather then using picasso library
I'm using tab layout And my Frament.java
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(
R.layout.fragment, container, false);
return rootView;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final ArrayList<Website> babyList = Website.getbabyFromFile("baby&kids.json", getActivity());
adapter = new WebsiteAdapter(this, babyList);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(),2));
recyclerView.setAdapter(adapter);
}
My Website.java is
private String url;
public String imageUrl;
public Website() {
}
public Website(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public static ArrayList<Website> getbabyFromFile(String filename, Context context) {
final ArrayList<Website> babyList = new ArrayList<>();
try {
// Load data
String jsonString = loadJsonFromAsset("baby&kids.json", context);
JSONObject json = new JSONObject(jsonString);
JSONArray baby = json.getJSONArray("baby&kids");
// Get Website objects from data
for(int i = 0; i < baby.length(); i++){
Website recipe = new Website();
recipe.setUrl(baby.getJSONObject(i).getString("url"));
babyList.add(recipe);
}
} catch (JSONException e) {
e.printStackTrace();
}
return babyList;
}
private static String loadJsonFromAsset(String filename, Context context) {
String json = null;
try {
InputStream is = context.getAssets().open(filename);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
}
catch (java.io.IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
And this is my WebsitAdapter.java
private Fragment mContext;
// private LayoutInflater mInflater;
private ArrayList<Website> mDataSource;
OnItemClickListener mItemClickListener;
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
//each data item is just a string in this case
public TextView url;
public ImageView thumbnailImageView;
public ViewHolder(View v) {
super(v);
url = (TextView) v.findViewById(R.id.websitename_id);
thumbnailImageView = (ImageView) v.findViewById(R.id.website_image_id);
v.setOnClickListener(this);
}
#Override
public void onClick(View view) {
Intent detailIntent = new Intent(view.getContext(), Webview.class);
detailIntent.putExtra("url", url.getText().toString());
mContext.startActivity(detailIntent);
}
}
public interface OnItemClickListener{
public void onItemClick(View view, int Position);
}
public void SetOnItemClickListner(final OnItemClickListener mItemClickListener){
this.mItemClickListener = mItemClickListener;
}
public WebsiteAdapter(Fragment context, ArrayList<Website> items) {
mContext = context;
mDataSource = items;
// mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.cardview_item_website, parent, false);
return new ViewHolder(itemView);
}
#Override
public void onBindViewHolder(WebsiteAdapter.ViewHolder holder, int position) {
// - get element from arraylist at this position
// - replace the contents of the view with that element
Website website = mDataSource.get(position);
holder.url.setText(website.getUrl());
//Picasso.with(mContext).load(website.imageUrl).placeholder(R.mipmap.ic_launcher).into(holder.thumbnailImageView);
}
#Override
public int getItemCount() {
return mDataSource.size();
}
And My output is
Please give me a solution that if theres is any possible ways to display images that is stored on drawable folder
If you have local images under drawable folder for all a) myntra b) firstCry c) hopscotch etc. Then you just simply need to get the correct drawable based on url.
You can create Factory class which will give you the #DrawableRes
public static #DrawableRes int getDrawable(String url){
if(url.contains("Myntra")) {
return R.drawable.myntra;
} else if(url.contains("Snapdeal")) {
return R.drawable.snapdeal;
}
// Add other if else to support other website url
}
Here is the modified onBindViewHolder method.
#Override
public void onBindViewHolder(WebsiteAdapter.ViewHolder holder, int position) {
Website website = mDataSource.get(position);
holder.url.setText(website.getUrl());
holder.thumbnailImageView.setImageResource(getDrawable(website.getUrl()));
}
I have a gridview which should show emojies that are retrieved from the server as urls, I was able to retrieve the urls and put it inside an arraylist, however using the gridview adapter, no images show at all, I've tried debugging by handcoding the url outside the for loop and it showed the image, which means that nothing is wrong with my adapter, also when I try to hardcode the url inside the for loop like arraylist.add("the url") no image appears, here's my code, please advise why the images are not showing, appreciate your assistance
BottomSheetDialog_Smiles.java
Communicator.getInstance().on("subscribe start", new Emitter.Listener() {
#Override
public void call(Object... args) {
try {
JSONDictionary response = (JSONDictionary) args[0];
String str = response.get("emojiPack").toString();
JSONArray emojies = new JSONArray(str);
for (int i = 0; i < emojies.length(); i++) {
JSONObject response2 = (JSONObject)
emojies.getJSONObject(i);
emojiModel = new EmojiModel((String)
response2.get("urlFile"));
emojiUrl = emojiModel.getEmojiFile();
JSONDictionary t =
JSONDictionary.fromString(response2.toString());
emojiModel.init(t);
emojieModels.add(emojiModel);
}
ImageAdapter2 emojiAdapter = new
ImageAdapter2(getApplicationContext(), emojieModels);
gridView2.setAdapter(emojiAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
ImageAdapter2.java
public class ImageAdapter2 extends BaseAdapter {
private Context context;
private ArrayList<String> emojieImages = new ArrayList<String>();
// Constructor
public ImageAdapter2(Context context, ArrayList<String>
emojieImagesList) {
this.context = context;
this.emojieImages = emojieImagesList;
}
#Override
public int getCount() {
return emojieImages.size();
}
#Override
public Object getItem(int position) {
return emojieImages.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public class Holder {
ImageView imageView;
}
#Override
public View getView(final int position, View convertView, ViewGroup
parent) {
Holder holder = new Holder();
LayoutInflater inflater = (LayoutInflater)
getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.smiles_items_layout, null);
holder.imageView = (ImageView)
grid.findViewById(R.id.smile_image_view);
Picasso.with(getApplicationContext())
.load(emojieImages.get(position))
.fit()
.centerInside()
.into(holder.imageView);
return grid;
}
}
EmojiModel.java
public class EmojiModel {
private int id;
private int price;
public String urlFile;
public EmojiModel(String urlFile) {
this.id=id;
this.price=price;
this.urlFile=urlFile;
}
public String getEmojiFile() {
return urlFile;
}
public void init(JSONDictionary data){
try{
urlFile = (String) data.get("urlFile");
id = Integer.parseInt((String) data.get("id"));
price = Integer.parseInt((String) data.get("price"));
}catch(Exception e){
e.printStackTrace();
}
}
}
Try this
Picasso.with(this)
.load(imageUrl)
.fit()
.centerInside()
.into(imageViewFromUrl, new Callback() {
#Override
public void onSuccess() {
Log.i(TAG, "succcess");
}
#Override
public void onError() {
Log.i(TAG, "error");
}
}
);
i make a java class names contact that is contain setter and getter for string value ,and make a class names contactAdapter extends ArrayAdapter the problem is all the data i return from JSON displayed but every item in ListView not clickable! I think is the problem in contactAdapter class
my contactAdapter class is :
public class contactadapter extends ArrayAdapter {
List list=new ArrayList();
public contactadapter(Activity activity, int resource) {
super(activity, resource);
}
public void add(contact object) {
super.add(object);
list.add(object);
}
#Override
public int getCount() {
return list.size();
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View matches;
matches=convertView;
contactholder contactholder;
if(matches==null){
LayoutInflater layoutInflater=(LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
matches=layoutInflater.inflate(R.layout.matches,null);
contactholder=new contactholder();
contactholder.team1=(TextView)matches.findViewById(R.id.tv1);
contactholder.team2=(TextView)matches.findViewById(R.id.tv2);
contactholder.date=(TextView)matches.findViewById(R.id.date);
contactholder.time=(TextView)matches.findViewById(R.id.time);
matches.setTag(contactholder);
}
else{
contactholder=(contactholder) matches.getTag();
}
contact contact=(contact) this.getItem(position);
contactholder.team1.setText(contact.getTeam1());
contactholder.team2.setText(contact.getTeam2());
contactholder.date.setText(contact.getDate());
contactholder.time.setText(contact.getTime());
return matches;
}
#Nullable
#Override
public Object getItem(int position) {
return list.get(position);
}
private class contactholder{
TextView team1,team2,date,time;
}
public class t1 extends Fragment {
contactadapter contactadapter;
View rootView;
ProgressDialog pd;
ListView lv;
Button b;
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.t1, container,false);
pd = new ProgressDialog(getActivity());
pd.setMessage("تجميع المعلومات ...");
pd.show();
lv=(ListView)rootView.findViewById(R.id.lv);
contactadapter=new contactadapter(getActivity(),R.layout.matches);
lv.setAdapter(contactadapter);
new readdata1().execute("http://isatstudent10.xyz/getdata.php");
return rootView;
}
private class readdata1 extends AsyncTask<String,Void,String> {
String jsonstring;
#Override
protected String doInBackground(String... params) {
URL url = null;
try {
url = new URL(params[0]);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
while ((jsonstring = reader.readLine()) != null) {
stringBuilder.append(jsonstring + "\n");
}
reader.close();
inputStream.close();
httpURLConnection.disconnect();
return stringBuilder.toString().trim();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(String result) {
int count=0;
System.out.println(result);
try {
JSONObject joo=new JSONObject(result);
JSONArray array = joo.getJSONArray("server_response");
while (count < array.length()) {
JSONObject j = array.getJSONObject(count);
String team1 = j.getString("team1");
String team2=j.getString("team2");
String date=j.getString("date");
String time=j.getString("time");
contact contact=new contact(team1,team2,date,time);
contactadapter.add(contact);
count++;
}
lv.setAdapter(contactadapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println(i+" eejjjjjjjjjjj");
}
});
pd.dismiss();
super.onPostExecute(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Set setOnItemClickListener on your listview in a fragment like this:
yourListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "Position: " + position, Toast.LENGTH_LONG).show();
}
});
I have a custom ListAdapter. I want to download image for every list item. I try to download them in AsyncTask (I found this solution in other discuss on so), but for some reason I always receive communicate "SkImageDecoder::Factory returned null"
public class MainMenuListAdapter extends BaseAdapter {
private List<Event> _events;
private Context _activityContext;
public MainMenuListAdapter(List<Event> events, Context context) {
this._events = events;
this._activityContext = context;
}
#Override
public int getCount() {
return this._events.size();
}
#Override
public Object getItem(int position) {
return this._events.get(position);
}
#Override
public long getItemId(int position) {
return this._events.get(position).getId();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null)
{
LayoutInflater inflater = (LayoutInflater) this._activityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.mainmenu_list_item, parent,false);
}
Event e = (Event)getItem(position);
new DownloadImageTask((ImageView)convertView.findViewById(R.id.imageView1))
.execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
TextView tvName = (TextView)convertView.findViewById(R.id.name);
tvName.setText(e.getName());
TextView tvDescription = (TextView)convertView.findViewById(R.id.description);
tvDescription.setText(e.getDescription());
TextView tvDate = (TextView)convertView.findViewById(R.id.date);
tvDate.setText(e.getDate());
TextView tvAddress = (TextView)convertView.findViewById(R.id.address);
tvName.setText(e.getAddress());
return convertView;
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
String uri = Uri.parse(urldisplay)
.buildUpon()
.appendQueryParameter("key", "val")
.build().toString();
Bitmap mIcon11 = null;
try {
URL url = new URL(uri);
InputStream in = url.openStream();
mIcon11 = BitmapFactory.decodeStream(in);
return mIcon11;
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
I write client for kaltura media platform.
I have an activity "Video". In this activity I must display list of video with thumbnails
First of all, I download list of videos using kaltura api, and this works fine. Every video entry have a field thumbnailUrl, which point out to thumbnail for video.
When I download this thumbnails for videos, it's(thumbnails) downloads in incorrect order, some thumbnails not downloaded, some thumbnails repeated for other video, and some not downloaded.
This is code of callback if downloadind videos:
private void handleFetchvideoListTask(List<VideoObject> videoObjects){
LinearLayout videoListProgressBarContainer = (LinearLayout)mActivity.findViewById(R.id.videoListProgressBarContainer);
LinearLayout videoListViewContainer = (LinearLayout)mActivity.findViewById(R.id.videoListViewContainer);
videoListProgressBarContainer.setVisibility(View.GONE);
videoListViewContainer.setVisibility(View.VISIBLE);
ListView listView = (ListView)videoListViewContainer.findViewById(R.id.videoListView);
VideoListAdapter adapter = new VideoListAdapter((LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
adapter.setList(videoObjects);
listView.setAdapter(adapter);
DownloadThumbnailsTask task = new DownloadThumbnailsTask(videoObjects, adapter);
task.execute();
}
This is code of DownloadThumbnailsTask:
public class DownloadThumbnailsTask extends AsyncTask<List<VideoObject>, VideoObject, Void>{
private List<VideoObject> videoObjectList = null;
private List<VideoObject> toProcess = null;
private VideoListAdapter adapter = null;
public DownloadThumbnailsTask(List<VideoObject> videoObjectList, VideoListAdapter adapter){
this.videoObjectList = videoObjectList;
this.toProcess = new ArrayList<VideoObject>(videoObjectList);
this.adapter = adapter;
}
#Override
protected Void doInBackground(List<VideoObject>... lists) {
for(int i=0; i<toProcess.size(); i++){
VideoObject item = videoObjectList.get(i);
String urldisplay = item.getThumbnailUrl();
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
item.setThumbnail(mIcon11);
mIcon11 = null;
publishProgress(item);
}
return null;
}
#Override
protected void onProgressUpdate(VideoObject... values) {
if(values != null && values.length > 0){
VideoObject item = values[0];
videoObjectList.remove(item);
videoObjectList.add(item);
adapter.setList(videoObjectList);
adapter.notifyDataSetChanged();
}
}
#Override
protected void onPostExecute(Void aVoid) {
this.toProcess.clear();
this.toProcess = null;
}
}
This is code of adapter:
public class VideoListAdapter extends BaseAdapter {
private List<VideoObject> list;
private LayoutInflater layoutInflater;
public VideoListAdapter(LayoutInflater layoutInflater){
this.layoutInflater = layoutInflater;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int i) {
return list.get(i);
}
#Override
public long getItemId(int i) {
return list.get(i).getId();
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
if(view == null){
view = layoutInflater.inflate(R.layout.list_item_video, viewGroup, false);
}
ViewHolder viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
VideoObject item = getVideoObjectItem(i);
viewHolder.duration.setText(item.getFormattedDuration());
viewHolder.title.setText(item.getName());
if(item.getThumbnail() != null){
viewHolder.thumbnail.setImageBitmap(item.getThumbnail());
}
return view;
}
private VideoObject getVideoObjectItem(int position){
return (VideoObject) getItem(position);
}
public List<VideoObject> getList() {
return list;
}
public void setList(List<VideoObject> list) {
this.list = list;
}
public static class ViewHolder {
public final ImageView thumbnail;
public final TextView title;
public final TextView duration;
public ViewHolder(View view) {
this.thumbnail = (ImageView)view.findViewById(R.id.imgVideoThumbnail);
this.title = (TextView)view.findViewById(R.id.txtVideoName);
this.duration = (TextView)view.findViewById(R.id.txtVideoDuration);
}
}
}
And this is result of my code:
I noticed two things:
Inside doInBackground you are waiting
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
to complete before downloading the next image.
Try this:
protected Void doInBackground(List<VideoObject>... lists) {
for(final int i=0; i<toProcess.size(); i++){
try {
new Thread(){
#Override
public void run() {
VideoObject item = videoObjectList.get(i);
String urldisplay = item.getThumbnailUrl();
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
item.setThumbnail(mIcon11);
publishProgress(item);
}
}.start();
} catch (Exception e) {
Log.e("Error", e.getMessage());
}
}
return null;
}
#Override
protected void onProgressUpdate(VideoObject... values) {
adapter.notifyDataSetChanged();
}
I think this two lines is the problem:
videoObjectList.remove(item);
videoObjectList.add(item);
You're removing an item and adding again at the bottom. Just call notifyDataSetChanged after setting the bitmap.
Inside getView you're creating a new ViewHolder every time.
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
if(view == null){
view = layoutInflater.inflate(R.layout.list_item_video, viewGroup, false);
viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
}else{
viewHolder = view.getTag();
}
VideoObject item = getVideoObjectItem(i);
viewHolder.duration.setText(item.getFormattedDuration());
viewHolder.title.setText(item.getName());
if(item.getThumbnail() != null){
viewHolder.thumbnail.setImageBitmap(item.getThumbnail());
}
return view;
}
Do you get anything in your logcat? Maybe opening the stream or decoding fails. Are the images large?