private class SelectAccountListAdapter extends ArrayAdapter<String>{
private Context mContext;
private int mResId;
private int mDialogId;
private final float OPACITY=0.54f;//opacity不透明的
private List<SubscriptionInfo>mSubInfoList;
public SelectAccountListAdapter(List<SubscriptionInfo>subInfoList,
Context context,int resource,string[] arr,int dialogId){
super(context,resource,arr);
mContext=context;
mResId=resource;
mDialogId=dialogId;
mSubInfoList=subInfoList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView;
final ViewHolder holder;
if(convertView==null){
rowView=inflater.inflate(mResId, null);
holder=new ViewHolder();
holder.title=(TextView)rowView.findViewById(R.id.title);
holder.summary=(TextView)rowView.findViewById(R.id.summary);
holder.icon=(ImageView)rowView.findViewById(R.id.icon);
rowView.setTag(holder);
}else{
rowView=convertView;
holder=(ViewHolder)rowView.getTag();
}
final SubscriptionInfo sir=mSubInfoList.get(position);
if(sir==null){
holder.title.setText(getItem(position));
hodler.summary.setText("");
if(mDialogId==CALL_PICK){
setPhoneAccountIcon(holder,position);
}else{
holder.icon.setImageDrawable(getResource()
.getDrawable(R.drawable.ic_live_help));
}
mSimManagementExt.setSmsAutoItemIcon(holder.icon,mDialogId,postion);
mSimManagementExt.setCurrNetworkIcon(holder.icon,mDialogId,position);
holder.icon.setAlpha(OPACITY);
}else{
holder.title.setText(sir.getDisplayName());
holder.summary.setText(sir.getNumber());
holder.icon.setImageDrawable(sir.createIconBitmap(mContext));
holder.icon.setAlpha(1.0f);
}
return rowView;
}
private class ViewHolder{
TextView title;
TextView summary;
ImageView icon;
}
private void setPhoneAccountIcon(ViewHolder holder,int location){
String askFirst=getResources().getString(R.string.sim_calls_ask_first_prefs_title);
String lableString=getItem(location);
final TelecomManager telecomManager=TelecomManager.from(mContext);
List<PhoneAccountHandle> phoneAccountHandles=
telecomManager.getCallCapablePhoneAccounts();
if(!askFirst.equals(lableString)){
if(phoneAccountHandles.size()>1){
location=location-1;
}
PhoneAccount phoneAccount=null;
if(location>=0 && location<phoneAccountHandles.size()){
phoneAccount=
telecomManager.getPhoneAccount(phoneAccountHandles.get(location));
}
if(phoneAccount!=null){
holder.icon.setImageDrawable(phoneAccount.getIcon().loadDrawable(mContext));
}
}else{
holder.icon.setImageDrawable(getResources().getDrawable(R.drawable.ic_live_help));
}
}
}
继承ArrayAdapter类的实例
最新推荐文章于 2023-06-08 17:35:28 发布