ImageListAdapterpublic class ImageListAdapter extends android.widget.BaseAdapter implements android.widget.ListAdapterA general image list adapter. |
Fields Summary |
---|
private final android.view.LayoutInflater | mInflater | private final List | mData | private final int | mItemViewId | private final int | mImageId | private final int | mTextId | private final boolean | mAreAllItemsSelectable | private final int | mSeparatorId |
Constructors Summary |
---|
public ImageListAdapter(android.content.Context context, List data)
this(context, data, R.layout.imglist_item, R.id.image, R.id.text, R.id.separator);
| public ImageListAdapter(android.content.Context context, List data, int itemViewId, int imgId, int textId, int separatorId)
mData = data;
mItemViewId = itemViewId;
mImageId = imgId;
mTextId = textId;
mAreAllItemsSelectable = !data.contains(null);
mSeparatorId = separatorId;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
Methods Summary |
---|
public boolean | areAllItemsEnabled()
return mAreAllItemsSelectable;
| public int | getCount()
return mData.size();
| public java.lang.Object | getItem(int position)
return mData.get(position);
| public long | getItemId(int position)
return position;
| public android.view.View | getView(int position, android.view.View convertView, android.view.ViewGroup parent)
View v;
if (convertView == null) {
v = mInflater.inflate(mItemViewId, parent, false);
} else {
v = convertView;
}
setupView(position, v);
return v;
| public boolean | isEnabled(int position)
return mData.get(position) != null;
| private void | setupView(int position, android.view.View view)
ImageView iv = (ImageView) view.findViewById(mImageId);
TextView tv = (TextView)view.findViewById(mTextId);
View separator = view.findViewById(mSeparatorId);
if (!isEnabled(position)) {
if (iv != null) {
iv.setVisibility(View.GONE);
}
if (tv != null) {
tv.setVisibility(View.GONE);
}
if (separator != null) {
separator.setVisibility(View.VISIBLE);
}
} else {
if (separator != null) {
separator.setVisibility(View.GONE);
}
final ImageListItem item = mData.get(position);
if (iv != null) {
iv.setVisibility(View.VISIBLE);
iv.setImageDrawable(item.getDrawable());
}
if (tv != null) {
tv.setVisibility(View.VISIBLE);
tv.setText(item.getText());
}
}
|
|