package com.example.gajah.mydemo; 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.LinearLayout; import android.widget.TextView; import java.util.List; /** * Created by Andy on 2015/6/8. */ public class MySmsAdapter extends BaseAdapter { private int resource ; private List<smsdata> mdate ; private LayoutInflater mInflater ; private static boolean Read = false ; public MySmsAdapter (Context context ,int resource) { this.resource = resource ; this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void updateListDate (List<smsdata> mdate) { this.mdate = mdate; } public void cleanData() { this.mdate = null ; } public void setBoolean(boolean read) { this.Read = read ; } public boolean getBoolean () { return Read ; } @Override public int getCount() { if (mdate == null) return 0; return mdate.size(); } @Override public Object getItem(int position) { return mdate; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view ; if (convertView == null) { view = mInflater.inflate(resource,parent,false); } else { view = convertView ; } setLayout(position,view); return view; } private void setLayout(int position, View view) { smsdata data = mdate.get(position); if (data != null && view != null) { final TextView Tel = (TextView) view.findViewById(R.id.tel); if (Tel != null) { Tel.setText(data.getTel()); } final TextView Body = (TextView) view.findViewById(R.id.body); if (Body != null) { Body.setText(data.getBody()); } final TextView Date = (TextView) view.findViewById(R.id.date); if (Date != null) { Date.setText(data.getDate()); } final TextView counter = (TextView) view.findViewById(R.id.counter); if (counter != null) { if (Read) { data.setSmsCounter(mdate.size()); } counter.setText(String.valueOf(data.getSmsCounter())); } } } }
适配器的创建
最新推荐文章于 2022-10-12 17:38:51 发布