骚扰拦截的适配器很简单,只有一种View
package com.chb.myphonesave.adapter; import java.util.List; import android.content.Context; 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.chb.myphonesave.R; import com.chb.myphonesave.entity.BlackNumberInfo; public class BlackNumberAdapter extends BaseAdapter { private List<BlackNumberInfo> list; LayoutInflater layoutInflater; public BlackNumberAdapter(Context context, List<BlackNumberInfo> list) { layoutInflater = LayoutInflater.from(context); this.list = list; } public int getCount() { return list.size(); } public BlackNumberInfo getItem(int position) { return list.get(position); } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = layoutInflater.inflate( R.layout.abn_item, null); holder.tvNumber = (TextView) convertView .findViewById(R.id.black_tv_number); holder.tvMode = (TextView) convertView .findViewById(R.id.black_tv_mode); holder.ivDelete = (ImageView) convertView .findViewById(R.id.black_iv_delete); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } final BlackNumberInfo info = getItem(position); holder.tvNumber.setText(info.number); switch (info.mode) { case 1: holder.tvMode.setText("拦截电话"); break; case 2: holder.tvMode.setText("拦截短信"); break; case 3: holder.tvMode.setText("拦截电话和短信"); break; default: break; } return convertView; } class ViewHolder { public TextView tvNumber; public TextView tvMode; public ImageView ivDelete; } }
时间: 2024-10-13 21:49:11