- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
Post post = null;
ListViewHolder holder;
if (mAnimated == null)
mAnimated = new HashSet<Integer>();
if (mPostsFiltered == null) {
post = mPosts.get(position);
if (position > 10)
shouldNewPartOfPostsBeLoaded = true;
else if (position == 1) {
if (shouldNewPartOfPostsBeLoaded) {
shouldNewPartOfPostsBeLoaded = false;
onMainNewsClick(null, false);
}
}
} else {
post = mPostsFiltered.get(position);
if (mNewPosts != null && mNewPosts.size() > 0) {
mPosts.addAll(0, mNewPosts);
mNewPosts = new LinkedList<Post>();
notifyDataSetChanged();
}
}
View view;
int type = getItemViewType(position);
if (convertView == null) {
holder = new ListViewHolder();
if (type == ITEM_WITH_IMAGE) {
view = mInflater.inflate(R.layout.item_news_item_new,
null);
holder.thumb = (RustoriaCenterCroppedWebImageView) view
.findViewById(R.id.thumbnail);
holder.textOverlay = view.findViewById(R.id.text_overlay);
} else {
view = mInflater.inflate(
R.layout.item_news_item_no_image, null);
}
holder.title = (TextView) view.findViewById(R.id.title);
holder.author = (TextView) view.findViewById(R.id.author);
holder.commentsCount = (TextView) view
.findViewById(R.id.comment_count);
holder.time = (TextView) view.findViewById(R.id.time);
holder.likesSign = (ImageView) view
.findViewById(R.id.likes_sign);
holder.likesCount = (TextView) view
.findViewById(R.id.likes_count);
view.setTag(holder);
} else {
view = convertView;
holder = (ListViewHolder) view.getTag();
}
String blogName = "";
LinkedList<Blog> blogs = post.getBlogs();
if (blogs.size() > 0)
blogName = blogs.get(0).getName();
String userName = post.getUserName();
String postTitle = post.getPostTitle();
holder.title.setText(postTitle);
holder.author
.setText(post.getUserName()
+ (((blogName.length() > 1) && (!userName
.equals(blogName))) ? (" для «"
+ blogName + "»") : ("")));
holder.commentsCount.setText(String.valueOf(post
.getPostCommentsCount()));
holder.time.setText(TimeUtils.formatDateCaption(
MainActivity.this, post.getDatetime(),
TimeUtils.getCurrentDatetime()));
int rating = post.getRating();
if (rating < 0)
holder.likesSign.setImageResource(R.drawable.minus);
else
holder.likesSign.setImageResource(R.drawable.plus);
holder.likesCount.setText(String.valueOf(Math.abs(rating)));
String imgName = post.getPreviewImageUrl();
if (imgName != null && holder.thumb != null && type == ITEM_WITH_IMAGE) {
String thumbUrl = NetworkUtils.getImageUrlByName(
MainActivity.this, imgName,
(mOldAndroid) ? ("200") : ("400"));
holder.thumb.setDimenstions(post.getImageWidth(imgName),
post.getImageHeight(imgName));
holder.thumb.setTag(thumbUrl);
holder.thumb.setImageURL(thumbUrl);
holder.textOverlay.setBackgroundColor(Color.TRANSPARENT);
Это из андроид-проекта. Вот такой вот getView в адаптере для ListView, в котором рекомендуют писать коротко и читабельно. Жаль весь не поместился:)