public View getView(int position, View convertView, ViewGroup parent) { final View view = (convertView != null) ? convertView : LayoutInflater.from(parent.getContext()) .inflate(R.layout.bookmark_item, parent, false); final ImageView imageView = (ImageView) view.findViewById(R.id.bookmark_item_icon); final TextView textView = (TextView) view.findViewById(R.id.bookmark_item_text); final TextView bookTitleView = (TextView) view.findViewById(R.id.bookmark_item_booktitle); final Bookmark bookmark = getItem(position); if (bookmark == null) { imageView.setVisibility(View.VISIBLE); imageView.setImageResource(R.drawable.ic_list_plus); textView.setText(ZLResource.resource("bookmarksView").getResource("new").getValue()); bookTitleView.setVisibility(View.GONE); } else { imageView.setVisibility(View.GONE); textView.setText(bookmark.getText()); if (myCurrentBook) { bookTitleView.setVisibility(View.GONE); } else { bookTitleView.setVisibility(View.VISIBLE); bookTitleView.setText(bookmark.getBookTitle()); } } return view; }
@Override public View getView(int position, View convertView, final ViewGroup parent) { final Item item = getItem(position); final View view; if (convertView != null && item.getClass().equals(convertView.getTag())) { view = convertView; } else { view = getLayoutInflater() .inflate( item instanceof SectionItem ? R.layout.catalog_manager_section_head : R.layout.catalog_manager_item, null); view.setTag(item.getClass()); } if (item instanceof SectionItem) { ((TextView) view.findViewById(R.id.catalog_manager_section_head_title)) .setText(((SectionItem) item).Title); } else /* if (item instanceof CatalogItem) */ { final CatalogItem catalogItem = (CatalogItem) item; if (myCoverManager == null) { view.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final int coverHeight = view.getMeasuredHeight(); myCoverManager = new CoverManager(CatalogManagerActivity.this, coverHeight * 15 / 22, coverHeight); view.requestLayout(); } final INetworkLink link = catalogItem.Tree.getLink(); ((TextView) view.findViewById(R.id.catalog_manager_item_title)).setText(link.getTitle()); ((TextView) view.findViewById(R.id.catalog_manager_item_subtitle)) .setText(link.getSummary()); final ImageView coverView = (ImageView) view.findViewById(R.id.catalog_manager_item_icon); if (!myCoverManager.trySetCoverImage(coverView, catalogItem.Tree)) { coverView.setImageResource(R.drawable.ic_list_library_books); } final CheckBox checkBox = (CheckBox) view.findViewById(R.id.catalog_manager_item_checkbox); checkBox.setChecked(catalogItem.IsChecked); checkBox.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { catalogItem.IsChecked = checkBox.isChecked(); setResultIds(catalogItem, 0); } }); } return view; }
private void downloadProfilePicture( final String profileId, URI pictureURI, final ImageView imageView) { if (pictureURI == null) { return; } // If we don't have an imageView, we are pre-fetching this image to store in-memory because we // think the user might scroll to its corresponding list row. If we do have an imageView, we // only want to queue a download if the view's tag isn't already set to the URL (which would // mean // it's already got the correct picture). boolean prefetching = imageView == null; if (prefetching || !pictureURI.equals(imageView.getTag())) { if (!prefetching) { // Setting the tag to the profile ID indicates that we're currently downloading the // picture for this profile; we'll set it to the actual picture URL when complete. imageView.setTag(profileId); imageView.setImageResource(getDefaultPicture()); } ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureURI) .setCallerTag(this) .setCallback( new ImageRequest.Callback() { @Override public void onCompleted(ImageResponse response) { processImageResponse(response, profileId, imageView); } }); ImageRequest newRequest = builder.build(); pendingRequests.put(profileId, newRequest); ImageDownloader.downloadAsync(newRequest); } }