** АДАПТЕР КУРСОРА И РИСУНОК ДЕРЖАТЕЛЯ ПРОСМОТРА
/**
* Adapter that allows us to match product items to layout fragment<p/>
*
* @author The Solar Sheriff
*/
public class MyItemListAdapter extends CursorAdapter {
public final static String TAG = "MyItemListAdapter";
/**
* Constructor from a list of items
*/
private LayoutInflater _li;
private Context _context;
private Cursor _in;
private int _productName,
_count;
public OrderItemListAdapter(Context _Context, Cursor _In) {
super(_Context, _In, true);
_context = _Context;
_li = LayoutInflater.from(_context);
_in = _In;
_productName = _in.getColumnIndex("product_name");
_count = _in.getCount();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public int getCount() {
return _in.getCount();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View _view = _li.inflate(R.layout.list_item_layout, null);
return _view;
}
private ViewHolder mapItemViewHolder(View _v){
ViewHolder _itemHolder = new ViewHolder();
//Map the views to the ViewHolder
_itemHolder.productName = (TextView) _v.findViewById(R.id.itemProductName);
return _itemHolder;
}
@Override
public void bindView(View _cView, final Context _context, final Cursor _c) {
ViewHolder _itemHolder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (_cView == null) {
_cView = _li.inflate(R.layout.list_item_layout, null);
_itemHolder = mapItemViewHolder(_cView);
_cView.setTag(_itemHolder);
}
else {
// Get the ViewHolder back to get fast access
// Can also get a view with no tag so check for null
if ((_itemHolder = (ViewHolder) _cView.getTag()) == null) {
_itemHolder = mapItemViewHolder(_cView);
_cView.setTag(_itemHolder);
}
}
//*** TEXT VIEWS ***
// Bind the data using the holder.
_itemHolder.productName.setText(_c.getString(_productName));
for(String _display : TabLayouts ) {
if ( _display.equals("WEB") ) _itemHolder.productName.setTag(Integer.toString(R.layout.WEB_layout));
if ( _display.equals("IPHONE") ) _itemHolder.productName.setTag(Integer.toString(R.layout.IPHONE_layout));
if ( _display.equals("ANDROID") ) _itemHolder.productName.setTag(Integer.toString(R.layout.ANDROID_layout));
}
}
static String TabLayouts = { "WEB","IPHONE","ANDROID"};
static class ViewHolder
{
TextView productName;
}
}
// ВАШ СЛУЖБА onSelectedItem ДЕЛАЕТ
MyList.setOnItemSelectedListener( new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> _item, View _View, int _selection, long _id) {
ViewGroup _parent = (ViewGroup)_item.getParent();
TextView _productName = (TextView)_parent.findViewById(R.id.itemProductName);
int _showLayout = Integer.valueOf(_productName.getTag());
//*** e.g. Inflate your fragment layout ***
}
});
Надеюсь, что это даетвам успешный путь, чтобы следовать:)