Ciao ragazzi, ho un problema con la listView che sto facendo:
praticamente ho creato una custom listView che prenda un listAdapter esteso da me per visualizzare una imageView solo quando č presente nel database, il problema č che riesco a visualizzare solo la prima riga e basta, e non capisco se č questione del cursore oppure č perchč da qualche parte (e non so dove) dovrei dire di andare alla posizione successiva del cursore, potete aiutarmi?
Questo č il codice per la popolazione della listView
codice:
// Create the item list
startManagingCursor(list);
String[] from = new String[] { ListDbAdapter.KEY_NAME};
int[] to = new int[] { R.id.text1};
// Now create an array adapter and set it to display using our row
EfficientAdapter listAdapter = new EfficientAdapter(this,
R.layout.manga_row, list, from, to);
setListAdapter(listAdapter);
e questo č il custom adapter:
codice:
private static class EfficientAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
private int layout;
private Bitmap mIcon1;
private String[] from;
private Context context;
private int[] to;
public EfficientAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
// Cache the LayoutInflate to avoid asking for a new one each time.
this.context=context;
this.layout=layout;
this.from=from;
this.to=to;
// Icons bound to the rows.
mIcon1 = BitmapFactory.decodeResource(context.getResources(), android.R.drawable.star_big_on);
}
@Override
public int getCount() {
return this.from.length;
}
@Override
public Object getItem(int position) {
return this.to[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// 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 (convertView == null) {
mInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(layout, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.text1);
holder.number = (TextView) convertView.findViewById(R.id.text2);
holder.icon = (ImageView) convertView.findViewById(R.id.tick);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
Cursor cursor = getCursor();
// Bind the data efficiently with the holder.
cursor.moveToPosition(position);
String name = cursor.getString(cursor.getColumnIndex(ListDbAdapter.KEY_NAME));
String number = cursor.getString(cursor.getColumnIndex(ListDbAdapter.KEY_NUMBER));
int presence = cursor.getInt(cursor.getColumnIndex(ListDbAdapter.KEY_PRESENCE));
holder.name.setText(name);
holder.number.setText(number);
if (presence != 0) holder.icon.setImageBitmap(mIcon1);
return convertView;
}
static class ViewHolder {
TextView name;
TextView number;
ImageView icon;
}
}
Potete darmi una mano? Cosa sbaglio?