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
e questo è il custom adapter: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);
Potete darmi una mano? Cosa sbaglio?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; } }

LinkBack URL
About LinkBacks
Rispondi quotando
