Android MaoZhuaWeiBo Adapter ListView最佳化及發送微博 - 4

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   ar   os   java   

這一篇主要給大家說說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);}@Overridepublic int getCount() {return mresult.size();}@Overridepublic Object getItem(int position) {return mresult.get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic 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://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://download.csdn.net/detail/jspping/8117425" target="_blank">http://download.csdn.net/detail/jspping/8117425</a><strong><span style="font-size:14px;color:#ff0000;"></span></strong><pre name="code" class="java">
OK,東西又不是很多,關鍵是掌握方法



Android MaoZhuaWeiBo Adapter ListView最佳化及發送微博 - 4

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.