Android应用开发-小巫CSDN博客客户端之获取评论列表,安卓cpu内存监控
@Overridepublic void onClick(View v) {
System.out.println("click");
reLoadImageView.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.VISIBLE);
new MainTask().execute(Constants.DEF_TASK_TYPE.REFRESH);
}
});
backBtn = (ImageView) findViewById(R.id.backBtn);
backBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
commentTV = (TextView) findViewById(R.id.comment);
listView = (XListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
listView.setPullRefreshEnable(this);
listView.setPullLoadEnable(this);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
@Override
public void finish() {
super.finish();
// 退出动画
overridePendingTransition(R.anim.push_no, R.anim.push_right_out);
}
private class MainTask extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(String... params) {
// 获得返回json字符串
String temp = HttpUtil.httpGet(URLUtil.getCommentListURL(filename,
page.getCurrentPage()));
if (temp == null) {
return Constants.DEF_RESULT_CODE.ERROR;
}
// 获得评论列表
List<Comment> list = JsoupUtil.getBlogCommentList(temp,
Integer.valueOf(page.getCurrentPage()), pageSize);
if (list.size() == 0) {
return Constants.DEF_RESULT_CODE.NO_DATA;
}
if (params.equals(Constants.DEF_TASK_TYPE.LOAD)) {
adapter.addList(list);
return Constants.DEF_RESULT_CODE.LOAD;
} else {
adapter.setList(list);
return Constants.DEF_RESULT_CODE.REFRESH;
}
}
@Override
protected void onPostExecute(Integer result) {
if (result == Constants.DEF_RESULT_CODE.ERROR) {
Toast.makeText(getApplicationContext(), "网络信号不佳",
Toast.LENGTH_SHORT).show();
listView.stopRefresh(DateUtil.getDate());
listView.stopLoadMore();
reLoadImageView.setVisibility(View.VISIBLE);
} else if (result == Constants.DEF_RESULT_CODE.NO_DATA) {
Toast.makeText(getApplicationContext(), "无更多评论",
Toast.LENGTH_SHORT).show();
listView.stopLoadMore();
listView.stopRefresh(DateUtil.getDate());
commentTV.setText("共有评论:" + commentCount);
} else if (result == Constants.DEF_RESULT_CODE.LOAD) {
page.addPage();
pageIndex++;
adapter.notifyDataSetChanged();
listView.stopLoadMore();
} else if (result == Constants.DEF_RESULT_CODE.REFRESH) {
adapter.notifyDataSetChanged();
listView.stopRefresh(DateUtil.getDate());
page.setPage(2);
commentTV.setText("共有评论:" + commentCount); // 显示评论数
}
progressBar.setVisibility(View.INVISIBLE);
super.onPostExecute(result);
}
}
// 加载更多
@Override
public void onLoadMore() {
new MainTask().execute(Constants.DEF_TASK_TYPE.LOAD);
}
// 刷新评论
@Override
public void onRefresh() {
page.setPage(1);
new MainTask().execute(Constants.DEF_TASK_TYPE.REFRESH);
}
}
/BlogClient/src/com/xiaowu/blogclient/adapter/CommentAdapter.java
package com.xiaowu.blogclient.adapter;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.xiaowu.blogclient.R;
import com.xiaowu.blogclient.model.Comment;
import com.xiaowu.blogclient.util.Constants;
/**
[*]评论列表适配器
[*]
[*]@author wwj_748
[*]
*/
public class CommentAdapter extends BaseAdapter {
private ViewHolder holder;
private LayoutInflater layoutInflater;
private Context context;
private List<Comment> list;
private SpannableStringBuilder htmlSpannable;
private ImageLoader imageLoader = ImageLoader.getInstance();
private DisplayImageOptions options;
private String replyText;
public CommentAdapter(Context c) {
super();
layoutInflater = (LayoutInflater) LayoutInflater.from(c);
list = new ArrayList<Comment>();
imageLoader.init(ImageLoaderConfiguration.createDefault(c));
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.csdn)
.showImageForEmptyUri(R.drawable.csdn)
.showImageOnFail(R.drawable.csdn)
.cacheInMemory().cacheOnDisc()
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new FadeInBitmapDisplayer(300)).build();
}
public void setList(List<Comment> list) {
this.list = list;
}
public void addList(List<Comment> list) {
this.list.addAll(list);
}
public void clearList() {
this.list.clear();
}
public List<Comment> getList() {
return list;
}
public void removeItem(int position) {
if (list.size() > 0) {
list.remove(position);
}
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Comment item = list.get(position); // 获取评论项
if (null == convertView) {
holder = new ViewHolder();
switch (item.getType()) {
case Constants.DEF_COMMENT_TYPE.PARENT: // 父项
convertView = layoutInflater.inflate(R.layout.comment_item,
null);
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.content = (TextView) convertView
.findViewById(R.id.content);
holder.date = (TextView) convertView.findViewById(R.id.date);
holder.reply = (TextView) convertView
.findViewById(R.id.replyCount);
holder.userface = (ImageView) convertView.findViewById(R.id.userface);
break;
case Constants.DEF_COMMENT_TYPE.CHILD: // 子项
convertView = layoutInflater.inflate(
R.layout.comment_child_item, null);
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.content = (TextView) convertView
.findViewById(R.id.content);
holder.date = (TextView) convertView.findViewById(R.id.date);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (null != item) {
switch (item.getType()) {
case Constants.DEF_COMMENT_TYPE.PARENT: // 主题项
holder.name.setText(item.getUsername());
holder.content.setText(Html.fromHtml(item.getContent())); // 显示评论内容
holder.date.setText(item.getPostTime());
// holder.reply.setText(item.getReplyCount());
imageLoader.displayImage(item.getUserface(), holder.userface, options);// 显示头像
break;
case Constants.DEF_COMMENT_TYPE.CHILD: // 回复项
holder.name.setText(item.getUsername());
replyText = item.getContent().replace("", "【");
replyText = replyText.replace("", "】");
holder.content.setText(Html.fromHtml(replyText));
holder.date.setText(item.getPostTime());
break;
default:
break;
}
}
return convertView;
}
@Override
public int getViewTypeCount() {
return 2;
尾声
如果你想成为一个优秀的 Android 开发人员,请集中精力,对基础和重要的事情做深度研究。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。
这里,笔者分享一份从架构哲学的层面来剖析的视频及资料分享给大家梳理了多年的架构经验,筹备近6个月最新录制的,相信这份视频能给你带来不一样的启发、收获。
https://s2.51cto.com/images/20211229/1640791249213736.jpg
Android进阶学习资料库
一共十个专题,包括了Android进阶所有学习资料,Android进阶视频,Flutter,java基础,kotlin,NDK模块,计算机网络,数据结构与算法,微信小程序,面试题解析,framework源码!
https://s2.51cto.com/images/20211229/1640791249839610.jpg
大厂面试真题
PS:之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
https://s2.51cto.com/images/20211229/1640791250556549.jpg
《2019-2021字节跳动Android面试历年真题解析》
https://s2.51cto.com/images/20211229/1640791250627209.jpg
[*]自行下载直达领取链接:【GitHub】
[*]以上进阶BATJ大厂学习资料可以免费分享给大家,需要完整版的朋友,【点这里可以看到全部内容】。
https://blog.51cto.com/u_15465282/4859982
页:
[1]