Robin,
This blog post describes something pretty close to what I think you are
trying to do:
http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
-- Kostya
01.03.2011 21:34, Robin Talwar ?????:
Sorry couldnt manage to get the screenshot some problem in my sdk i guess.
Though i can share the code of my list item
package com.hungama.myplay.utils;
import java.io.IOException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hungama.myplay.activity.R;
import com.hungama.myplay.model.Album;
import com.hungama.myplay.model.Category;
import com.hungama.myplay.model.DownloadPlan;
import com.hungama.myplay.model.SearchElement;
import com.hungama.myplay.model.Track;
import com.hungama.myplay.model.VideoElement;
public class ListItemView extends LinearLayout {
private Activity activity;
private Track track;
private Album album;
private Category category;
private int resId;
private ImageView iv_thumb;
private VideoElement video;
private int bgColor = -1;
private SearchElement searchElement;
private byte searchType;
private boolean isPlaylistItem;
private DownloadPlan plan;
public ListItemView(Activity context, AttributeSet attrs) {
super(context, attrs);
activity = context;
}
public ListItemView(Activity context, int resId, Track track) {
super(context);
activity = context;
this.track = track;
this.resId = resId;
addView(getListElementView());
}
public ListItemView(Activity context, int resId, Track track,
boolean isPlaylistItem) {
super(context);
activity = context;
this.track = track;
this.resId = resId;
this.isPlaylistItem = isPlaylistItem;
addView(getListElementView());
}
public ListItemView(Activity context, int resId,
SearchElement searchElement, byte searchType) {
super(context);
this.searchType = searchType;
activity = context;
this.searchElement = searchElement;
this.resId = resId;
addView(getListElementView());
}
public ListItemView(Activity context, int resId, Album album) {
super(context);
activity = context;
this.album = album;
this.resId = resId;
addView(getListElementView());
}
public ListItemView(Activity context, int resId, VideoElement video) {
super(context);
activity = context;
this.video = video;
this.resId = resId;
addView(getListElementView());
}
public ListItemView(Activity context, int resId, DownloadPlan plan) {
super(context);
activity = context;
this.plan = plan;
this.resId = resId;
addView(getListElementView());
}
public ListItemView(Activity activity2, int listElementView, int grey,
Category category2) {
super(activity2);
activity = activity2;
this.category = category2;
this.resId = listElementView;
bgColor = grey;
addView(getListElementView());
}
private View getListElementView() {
LayoutInflater inflater = activity.getLayoutInflater();
View ConvertView = inflater.inflate(resId, null);
LinearLayout linearLayout = (LinearLayout) ConvertView
.findViewById(R.id.l_list_element_super_view);
if (plan == null) {
iv_thumb = (ImageView)
ConvertView.findViewById(R.id.iv_thumbnail);
ImageButton imageButton = (ImageButton) ConvertView
.findViewById(R.id.imb_download);
if (!isPlaylistItem) {
FetchImage fetchImage = new FetchImage();
fetchImage.execute();
} else {
iv_thumb.setImageResource(R.drawable.music);
imageButton.setVisibility(View.GONE);
}
TextView tv_title = (TextView) ConvertView
.findViewById(R.id.tv_list_element_title);
TextView tvSecondLine = (TextView) ConvertView
.findViewById(R.id.tv_list_element_album);
if (this.track != null) {
TextView tv_albumName = (TextView) ConvertView
.findViewById(R.id.tv_list_element_album);
tv_albumName.setText(track.getAlbum());
if (track.getTitle() != null) {
tv_title.setText(track.getTitle());
}
if (track.getAlbum() != null) {
tvSecondLine.setText(track.getAlbum());
}
} else if (this.album != null) {
imageButton.setVisibility(View.GONE);
if (album.getAlbumName() != null) {
tv_title.setText(album.getAlbumName());
}
} else if (this.category != null) {
tv_title.setText(category.getName());
imageButton.setVisibility(View.GONE);
} else if (this.video != null) {
if (video.getTitle() != null) {
tv_title.setText(video.getTitle());
}
if (video.getAlbum() != null) {
tvSecondLine.setText(video.getAlbum());
}
} else if (this.searchElement != null) {
if (searchType == Constants.SEARCH_TRACK) {
tv_title.setText(searchElement.getTrackTitle());
if (searchElement.getAlbumTitle() != null) {
tvSecondLine.setText(searchElement.getAlbumTitle());
}
} else if (searchType == Constants.SEARCH_ALBUM) {
imageButton.setVisibility(View.GONE);
tv_title.setText(searchElement.getAlbumTitle());
if (searchElement.getReleaseDate() != null) {
tvSecondLine.setText(searchElement.getReleaseDate());
}
} else if (searchType == Constants.SEARCH_ARTIST) {
imageButton.setVisibility(View.GONE);
tv_title.setText(searchElement.getArtistTitle());
}
}
// if (bgColor != -1) {
// linearLayout.setBackgroundColor(bgColor);
// }
} else {
TextView tv_title = (TextView) ConvertView
.findViewById(R.id.tv_name);
// tv_title.setText(plan.getName());
TextView tvSecondLine = (TextView) ConvertView
.findViewById(R.id.tv_desc);
// tvSecondLine.setText(plan.getDescription());
}
return linearLayout;
}
class FetchImage extends AsyncTask<Void, Void, Byte> {
protected Byte doInBackground(Void... params) {
URL uri = null;
try {
if (track != null) {
if (track.getImageUrl() != null) {
uri = new URL(track.getImageUrl());
}
} else if (album != null) {
if (album.getImageUrl() != null) {
uri = new URL(album.getImageUrl());
}
} else if (category != null) {
if (category.getImage() != null) {
uri = new URL(category.getImage());
}
} else if (video != null) {
if (video.getImageUrl() != null) {
uri = new URL(video.getImageUrl());
}
} else if (searchElement != null
&& searchElement.getImageUrl() != null
&& !searchElement.getImageUrl()
.equalsIgnoreCase("null")) {
uri = new URL(searchElement.getImageUrl());
}
if (uri != null) {
final Bitmap bitmap = BitmapFactory.decodeStream(uri
.openConnection().getInputStream());
if (bitmap != null) {
activity.runOnUiThread(new Runnable() {
public void run() {
iv_thumb.setImageBitmap(bitmap);
}
});
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
}
On Tue, Mar 1, 2011 at 7:49 PM, TreKing <[email protected]
<mailto:[email protected]>> wrote:
On Tue, Mar 1, 2011 at 1:45 AM, Abhishek Talwar
<[email protected]
<mailto:[email protected]>> wrote:
Any help will be appreciated
It will be very difficult to help you with such generic, limited
information.
Post a screenshot of the problem, clarify what the issue is, and
show some relevant code.
-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> -
Chicago transit tracking app for Android-powered devices
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>
To unsubscribe from this group, send email to
[email protected]
<mailto:android-developers%[email protected]>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en