Android 사용자 정의 Adapter-SimpleAdapter 계승
5172 단어 자바androidSimpleAdapter
/**
* RemindView Adapter
*
* @author xzz
*
*/
public class RemindViewAdapter extends SimpleAdapter {
/**
* map list,map
*/
private List<? extends Map<String, ?>> mData;
/**
* xml id
*/
private int mResource;
/**
* RemindViewAdapter key
*/
private String[] mFrom;
/**
* RemindViewAdapter id
*/
private int[] mTo;
/**
*
*/
private LayoutInflater mInflater;
/**
* , null,
*/
private String[] mNewTextItem;
/**
*
*/
private ViewBinder mViewBinder;
/**
* ,
*
* @param context
* @param data
* @param resource
* @param from
* @param to
* @param newTextItem
* @see android.widget.SimpleAdapter
*/
public RemindViewAdapter(Context context,
List<? extends Map<String, ?>> data, int resource,
String[] from, int[] to, String[] newTextItem) {
super(context, data, resource, from, to);
mData = data;
mResource = resource;
mFrom = from;
mTo = to;
mNewTextItem = newTextItem;
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
/**
* @see android.widget.Adapter#getCount()
*/
public int getCount() {
return mData.size();
}
/**
* @see android.widget.Adapter#getItem(int)
*/
public Object getItem(int position) {
return mData.get(position);
}
/**
* @see android.widget.Adapter#getItemId(int)
*/
public long getItemId(int position) {
return position;
}
/**
* @see android.widget.Adapter#getView(int, View, ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
return createViewFromResource(position, convertView, parent,
mResource);
}
/**
*
* View
*
* @param position
*
* @param convertView
* @param parent
* @param resource
* @return
* @see android.widget.SimpleAdapter#createViewFromResource
*/
private View createViewFromResource(int position, View convertView,
ViewGroup parent, int resource) {
View v;
if (convertView == null) {
v = mInflater.inflate(resource, parent, false);
} else {
v = convertView;
}
bindView(position, v);
return v;
}
/**
* newItemText null, R.id.newtextitem
*
* @param position
* @param view listView item View
* @see android.widget.SimpleAdapter#bindView
*/
private void bindView(int position, View view) {
final Map<String, ?> dataSet = mData.get(position);
if (dataSet == null) {
return;
}
final ViewBinder binder = mViewBinder;
final String[] from = mFrom;
final int[] to = mTo;
final int count = to.length;
for (int i = 0; i < count; i++) {
final View v = view.findViewById(to[i]);
if (v != null) {
final Object data = dataSet.get(from[i]);
String text = data == null ? "" : data.toString();
boolean bound = false;
if (binder != null) {
bound = binder.setViewValue(v, data, text);
}
if (!bound) {
if (v instanceof TextView) {
setViewText((TextView) v, text);
if (from[i].equals(key[2])
&& mNewTextItem[position] == null)
// newItemText null, R.id.newtextitem
// ListView Item
v.setVisibility(View.INVISIBLE);
} else if (v instanceof ImageView) {
if (data instanceof Integer) {
setViewImage((ImageView) v, (Integer) data);
} else {
setViewImage((ImageView) v, text);
}
} else {
throw new IllegalStateException(
v.getClass().getName()
+ " is not a "
+ " view that can be bounds by this SimpleAdapter");
}
}
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.