适配器的创建

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()));
            }
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值