首页 > 代码库 > Android MaoZhuaWeiBo Adapter ListView优化及发送微博 - 4

Android MaoZhuaWeiBo Adapter ListView优化及发送微博 - 4

这一篇主要给大家说说Adapter ListView优化及发送微博,我们都知道Android在一些比较耗内存的类里,为了尽量避免浪费内

存,我们需要对我们的组件之类的进行优化,使其节约不必要的资源浪费


自定义适配器:

package com.neweriweibo.adapter;
/**
 * 适配器
 * @author Engineer-Jsp
 * @date 2014.10.28
 * */
import java.util.ArrayList;

import com.neweriweibo.R;
import com.neweriweibo.model.UserWeiBiInfo;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MessageAdapter extends BaseAdapter {  
	
	private Context mContext ;
	private ArrayList<UserWeiBiInfo> mresult ;
	private LayoutInflater layoutinflater;
	

	public MessageAdapter(Context context, ArrayList<UserWeiBiInfo> result) {
		mContext = context ;
		mresult = result ;
		layoutinflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mresult.size();
	}

	@Override
	public Object getItem(int position) {
		return mresult.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder ;
		View view = convertView ;
		if(view == null){
			holder = new ViewHolder() ;
			view =  layoutinflater.inflate(R.layout.message_list_item, null) ;
			holder.tvName = (TextView)view.findViewById(R.id.m_tv_username) ;
			holder.tvMessage = (TextView)view.findViewById(R.id.m_tv_message) ;
			holder.headimg = (ImageView)view.findViewById(R.id.weibo_item_icon);
			
			view.setTag(holder) ;
			 
		}else{
			holder = (ViewHolder) view.getTag() ;
		}
		Log.d("微博好友消息-用户名测试:", mresult.get(position).getName());
		holder.tvName.setText(mresult.get(position).getName());
		Log.d("微博好友消息-内容测试:", mresult.get(position).getOrigtext());
		holder.tvMessage.setText(mresult.get(position).getOrigtext());
		Log.d("微博好友消息-头像地址测试:", mresult.get(position).getHeadimg());
		Picasso.with(view.getContext().getApplicationContext()).load(mresult.get(position).getHeadimg()).into(holder.headimg);
		return view;
	}
	
	static class  ViewHolder{
		TextView tvName ;
		TextView tvMessage ;
		ImageView headimg;
	}

}

ViewHolder 就是ListView优化办法之一,屡试不爽
发送消息界面:
<img src=http://www.mamicode.com/"http://img.blog.csdn.net/20141104025947645?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvanNwcGluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />>
目前只带文本发送功能,表情包都在源代码里有,有兴趣的,可以继续开发,下面提供源码学习下载地址:
地址:<a target=_blank href=http://www.mamicode.com/"http://download.csdn.net/detail/jspping/8117425" target="_blank">http://download.csdn.net/detail/jspping/8117425
>
OK,东西又不是很多,关键是掌握方法


Android MaoZhuaWeiBo Adapter ListView优化及发送微博 - 4