| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.graphics.drawable.Drawable; |
| 21 |
import android.view.View; |
| 22 |
import android.view.ViewGroup; |
| 23 |
import android.widget.BaseAdapter; |
| 24 |
|
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
public class AccountViewAdapter extends BaseAdapter { |
| 28 |
|
| 29 |
private List<AccountElements> mData; |
| 30 |
private Context mContext; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public AccountViewAdapter(Context context, final List<AccountElements> data) { |
| 40 |
mContext = context; |
| 41 |
mData = data; |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public int getCount() { |
| 46 |
return mData.size(); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public Object getItem(int position) { |
| 51 |
return mData.get(position); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public long getItemId(int position) { |
| 56 |
return position; |
| 57 |
} |
| 58 |
|
| 59 |
public void updateData(final List<AccountElements> data) { |
| 60 |
mData = data; |
| 61 |
notifyDataSetChanged(); |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public View getView(int position, View convertView, ViewGroup parent) { |
| 66 |
AccountItemView view; |
| 67 |
if (convertView == null) { |
| 68 |
view = new AccountItemView(mContext); |
| 69 |
} else { |
| 70 |
view = (AccountItemView) convertView; |
| 71 |
} |
| 72 |
AccountElements elements = (AccountElements) getItem(position); |
| 73 |
view.setViewItem(elements); |
| 74 |
return view; |
| 75 |
} |
| 76 |
|
| 77 |
public static class AccountElements { |
| 78 |
private int mIcon; |
| 79 |
private Drawable mDrawable; |
| 80 |
private String mName; |
| 81 |
private String mNumber; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public AccountElements(int icon, String name, String number) { |
| 92 |
this(icon, null, name, number); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public AccountElements(Drawable drawable, String name, String number) { |
| 104 |
this(0, drawable, name, number); |
| 105 |
} |
| 106 |
|
| 107 |
private AccountElements(int icon, Drawable drawable, String name, String number) { |
| 108 |
mIcon = icon; |
| 109 |
mDrawable = drawable; |
| 110 |
mName = name; |
| 111 |
mNumber = number; |
| 112 |
} |
| 113 |
|
| 114 |
public int getIcon() { |
| 115 |
return mIcon; |
| 116 |
} |
| 117 |
public String getName() { |
| 118 |
return mName; |
| 119 |
} |
| 120 |
public String getNumber() { |
| 121 |
return mNumber; |
| 122 |
} |
| 123 |
public Drawable getDrawable() { |
| 124 |
return mDrawable; |
| 125 |
} |
| 126 |
} |
| 127 |
} |