Tom F M White wrote:
> TripleText is just an object for storing 4 strings, 3 for the text, 1
> for the image URL. Rest of the code follows, sorry it's quite long...
> 
> TripleTextView:
> 
> public class TripleTextView extends LinearLayout {
> 
>     private TextView mText1;
>     private TextView mText2;
>     private TextView mText3;
>     private String imageURL;
>     private ImageView image;
>     private Drawable imageDrawable;
>     public TripleTextView(Context context, TripleText tt) {
>         super(context);
> 
>         this.setOrientation(HORIZONTAL);
> 
>         //add image
>         imageURL = tt.getImageURL();
>         try {
>             Log.v("TTV","Loading Drawable from: "+imageURL);
>             imageDrawable = Drawable.createFromStream(new
> URL(imageURL).openStream(), "src");
> 
>             Log.v("TTV","Image created ok");
>         } catch (MalformedURLException e) {
>             Log.v("TTV","Malformed URL");
>         } catch (IOException e) {
>             Log.v("TTV","IO Exception");
>         }
>         image = new ImageView(context);
>         image.setImageDrawable(imageDrawable);
> 
>         addView(image,  new LinearLayout.LayoutParams(
>                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
>         LinearLayout subLayout = new LinearLayout(context);
>         subLayout.setOrientation(VERTICAL);
> 
>         mText1 = new TextView(context);
>         mText1.setText(tt.getText1());
> 
>         subLayout.addView(mText1,  new LinearLayout.LayoutParams(
>                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
> 
>         mText2 = new TextView(context);
>         mText2.setText(tt.getText2());
> 
>         subLayout.addView(mText2, new LinearLayout.LayoutParams(
>                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
>         mText3 = new TextView(context);
>         mText3.setText(tt.getText3());
> 
>         subLayout.addView(mText3, new LinearLayout.LayoutParams(
>                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
>         addView(subLayout, new LinearLayout.LayoutParams(
>                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
> 
>     }
> 
>     public void setText1(String words) {
>         mText1.setText(words);
>     }
> 
>     public void setText2(String words) {
>         mText2.setText(words);
>     }
>     public void setText3(String words) {
>         mText3.setText(words);
>     }
> 
>     public void setImageURL(String imageURL) {
>         this.imageURL = imageURL;
>     }
> }
> 
> TripleListAdapter:
> 
> public class TripleListAdapter extends BaseAdapter {
> 
>      private Context mContext;
> 
>      private List<TripleText> mItems = new ArrayList<TripleText>();
> 
>      public TripleListAdapter(Context context) {
>           mContext = context;
>      }
> 
>      public void addItem(TripleText it) { mItems.add(it); }
> 
>      public void setListItems(List<TripleText> lit) { mItems = lit; }
> 
>      public int getCount() { return mItems.size(); }
> 
>      public Object getItem(int position) { return mItems.get(position); }
> 
>      public boolean areAllItemsSelectable() { return false; }
> 
>      public boolean isSelectable(int position) {
>           try{
>                return mItems.get(position).isSelectable();
>           }catch (IndexOutOfBoundsException aioobe){
>                return false;
>           }
>      }
> 
>      public long getItemId(int position) {
>           return position;
>      }
>      public View getView(int position, View convertView, ViewGroup
> parent) {
>          TripleTextView ttv;
>           if (convertView == null) {
>                ttv = new TripleTextView(mContext, mItems.get(position));
>           } else {
>               ttv = (TripleTextView) convertView;
>               ttv.setText1(mItems.get(position).getText1());
>               ttv.setText2(mItems.get(position).getText2());
>               ttv.setText3(mItems.get(position).getText3());
>               ttv.setImageURL(mItems.get(position).getImageURL());
>           }
>           return ttv;
>      }
> }

In getView(), in the case where convertView is not null, you are calling
setImageURL(), then doing nothing with that value to actually load in
the replacement image.

Also, you are downloading the images on the main application thread.
That's going to be a problem -- your UI will freeze, and eventually
Android may kill it off with an "application not responding" error.
Please download your images off the main application thread, such as via
an AsyncTask.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 2.0 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to