Hi, Do you eventually see the bitmap in imageView, after it is loaded from the network ?
See the definitive example from Romain Guy - http://code.google.com/p/shelves/ And discussed here - http://www.curious-creature.org/2009/03/04/speed-up-your-android-ui/ Also no need to say a post is URGENT, we assume all posts are urgent anyway. Regards On Tuesday, July 24, 2012 9:44:30 AM UTC+10, Raghav Shankar wrote: > > I am working on an android application that has a custom listview that > contains an imageview and a textview. I am loading an image from the > internet and converting it into a bitmap image. I am doing this using an > async task. I am trying to display the bitmap in the imageview. When the > activity starts I am only able to see a black screen and I don't see any > listview. I would appreciate any help. Here is my code: > > public class CustomList { > > public Bitmap icon; > public String title; > public CustomList(){ > super(); > } > > public CustomList(Bitmap icon, String title) { > super(); > this.icon = icon; > this.title = title; > } > } > > > Here is my adapter class: > > > public class CustomListAdapter extends ArrayAdapter<CustomList> { > > Context context; > int layoutResourceId; > LinkedList<CustomList> data = new LinkedList<CustomList>(); > public CustomListAdapter(Context context, int layoutResourceId, > LinkedList<CustomList> data) { > super(context, layoutResourceId, data); > // TODO Auto-generated constructor stub > this.context = context; > this.layoutResourceId = layoutResourceId; > this.data = data; > } > > @Override > public View getView(int position, View convertView, ViewGroup parent) { > // TODO Auto-generated method stub > View row = convertView; > CustomListHolder holder = null; > if(row == null){ > LayoutInflater inflater = ((Activity)context).getLayoutInflater(); > row = inflater.inflate(layoutResourceId, parent, false); > holder = new CustomListHolder(); > > holder.text = (TextView)row.findViewById(R.id.txtTitle); > holder.thumbnail = (ImageView)row.findViewById(R.id.imgIcon); > row.setTag(holder); > } > else > holder = (CustomListHolder)row.getTag(); > CustomList cl = data.get(position); > holder.text.setText(cl.title); > if(cl.icon != null) > holder.thumbnail.setImageBitmap(cl.icon); > > return row; > } > static class CustomListHolder > { > ImageView thumbnail; > TextView text; > } > > } > > > Here is my main activity and it has an async class as a sub class: > > public class MainActivity extends Activity { > LinkedList<CustomList> list_data = new LinkedList<CustomList>(); > LinkedList<String> photo_url = new LinkedList<String>(); > LinkedList<String> list_title = new LinkedList<String>(); > ListView lv ; > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.list_main); > photo_url.add(0," > http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png > "); > list_title.add(0, "Android"); > LoadImage eventImageLoader = new LoadImage(MainActivity.this, > photo_url, list_title); > eventImageLoader.execute(); > > CustomListAdapter adapter = new > CustomListAdapter(this,R.layout.list_item, list_data); > lv = (ListView)findViewById(R.id.listView1); > lv.setAdapter(adapter); > > } > > public class LoadImage extends AsyncTask<Void, Void, > LinkedList<CustomList>>{ > > Context callingContext = null; > LinkedList<String> pic_url = new LinkedList<String>(); > LinkedList<String> title = new LinkedList<String>(); > Bitmap b = null; > LinkedList<Bitmap> bm = new LinkedList<Bitmap>(); > > public LoadImage(Context callingContext, LinkedList<String> pic_url, > LinkedList<String> title){ > > this.callingContext = callingContext; > this.pic_url = pic_url; > this.title = title; > } > > @Override > protected LinkedList<CustomList> doInBackground(Void... params) { > // TODO Auto-generated method stub > URL imageUrl; > CustomList temp; > for(int i = 0; i < pic_url.size(); i++) > { > try { > imageUrl = new URL(pic_url.get(i)); > temp = new > CustomList(BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream()),title.get(i)); > list_data.add(i,temp); > System.out.println("Added" + i + "th Value"); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > return list_data; > } > > protected void onPostExecute(LinkedList<CustomList> bm) { > // TODO Auto-generated method stub > super.onPostExecute(bm); > > } > } > } > -- 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

