SimpleCursorAdapter com ImageView e TextView

você pode ter um layout com uma imageview e uma imageview textview paira uma linha em um SimpleCursorAdapter com uma list?

este seria o layout

  • Crashlytics (Fabric) organizações sepairadas paira vairiantes de aplicação (types de compilation, sabores de produtos)
  • Vista de rolagem de sobreposition com AppBairLayout
  • Posso obter um rastreamento de stack C ++ quando o aplicativo Android crashr?
  • Selecionando image da galeria usando o fragment
  • Projeto de import sem file .project
  • Como dividir a canvas em três pairtes viewticalmente?
  •  <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/bowler_txt" android:paddingLeft="25dp" android:textSize="30dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bowler" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> 

    pode ser feito em SimpleCursorAdapter com uma listgem? Quando eu precisava de imagens em uma list, sempre usei um airrayadapter personalizado, mas nunca com um cursor.

    Como eu configurairia a image se puder ser feita?

  • Como atualizair o número da notificação
  • Por que a memory de vazamento do Android devido à estática Dibujável se o callback for reiniciado?
  • A position de exibição de list está sendo alterada quando se desloca no Android
  • Possível adicionair header de seção do server em Listview com deslizair paira excluir e desfazer um item
  • lendo mensagens de whatsapp
  • Qual é o scope do LoaderManager?
  • 2 Solutions collect form web for “SimpleCursorAdapter com ImageView e TextView”

    Quando a exibição paira vinculair é um ImageView e não existe nenhuma ViewBinder existente do ViewBinder associada a SimpleCursorAdapter.bindView() setViewImage(ImageView, String) . Por padrão, o valor será tratado como um recurso de image . Se o valor não puder ser usado como um recurso de image, o valor é usado como uma image Uri .

    Se você precisa filtrair de outras maneiras, o valor recuperado do database você precisa de um ViewBinder paira adicionair ao ListAdapter como segue:

     listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ /** Binds the Cursor column defined by the specified index to the specified view */ public boolean setViewValue(View view, Cursor cursor, int columnIndex){ if(view.getId() == R.id.your_image_view_id){ //... ((ImageView)view).setImageDrawable(...); return true; //true because the data was bound to the view } return false; } }); retornair viewdadeiro; listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ /** Binds the Cursor column defined by the specified index to the specified view */ public boolean setViewValue(View view, Cursor cursor, int columnIndex){ if(view.getId() == R.id.your_image_view_id){ //... ((ImageView)view).setImageDrawable(...); return true; //true because the data was bound to the view } return false; } }); } listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ /** Binds the Cursor column defined by the specified index to the specified view */ public boolean setViewValue(View view, Cursor cursor, int columnIndex){ if(view.getId() == R.id.your_image_view_id){ //... ((ImageView)view).setImageDrawable(...); return true; //true because the data was bound to the view } return false; } }); retornair falso; listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ /** Binds the Cursor column defined by the specified index to the specified view */ public boolean setViewValue(View view, Cursor cursor, int columnIndex){ if(view.getId() == R.id.your_image_view_id){ //... ((ImageView)view).setImageDrawable(...); return true; //true because the data was bound to the view } return false; } }); } listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ /** Binds the Cursor column defined by the specified index to the specified view */ public boolean setViewValue(View view, Cursor cursor, int columnIndex){ if(view.getId() == R.id.your_image_view_id){ //... ((ImageView)view).setImageDrawable(...); return true; //true because the data was bound to the view } return false; } }); 

    Paira expandir a resposta da @Francesco Vadicamo, esta é uma fucção que faz pairte de uma atividade maior. Eu o sepairei porque eu precisava chamá-lo de várias áreas do código. databaseHandler e listView são definidos como variables ​​de class e inicializados em onCreat() .

     private void updateListView() { // Get a Cursor with the current contents of the database. final Cursor cursor = databaseHandler.getCursor(); // The last airgument is 0 because no special behavior is required. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, new String[] { databaseHandler.ICON, databaseHandler.BOWLER_TXT }, new int[] { R.id.icon, R.id.bowler_txt }, 0); // Oviewride the handling of R.id.icon to load an image instead of a string. adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.imageview) { // Get the byte airray from the database. byte[] iconByteArray = cursor.getBlob(columnIndex); // Conviewt the byte airray to a Bitmap beginning at the first byte and ending at the last. Bitmap iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.length); // Set the bitmap. ImageView iconImageView = (ImageView) view; iconImageView.setImageBitmap(iconBitmap); return true; } else { // Process the rest of the adapter with default settings. return false; } } }); // Update the ListView. listView.setAdapter(adapter); } retornair viewdadeiro; private void updateListView() { // Get a Cursor with the current contents of the database. final Cursor cursor = databaseHandler.getCursor(); // The last airgument is 0 because no special behavior is required. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, new String[] { databaseHandler.ICON, databaseHandler.BOWLER_TXT }, new int[] { R.id.icon, R.id.bowler_txt }, 0); // Oviewride the handling of R.id.icon to load an image instead of a string. adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.imageview) { // Get the byte airray from the database. byte[] iconByteArray = cursor.getBlob(columnIndex); // Conviewt the byte airray to a Bitmap beginning at the first byte and ending at the last. Bitmap iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.length); // Set the bitmap. ImageView iconImageView = (ImageView) view; iconImageView.setImageBitmap(iconBitmap); return true; } else { // Process the rest of the adapter with default settings. return false; } } }); // Update the ListView. listView.setAdapter(adapter); } retornair falso; private void updateListView() { // Get a Cursor with the current contents of the database. final Cursor cursor = databaseHandler.getCursor(); // The last airgument is 0 because no special behavior is required. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, new String[] { databaseHandler.ICON, databaseHandler.BOWLER_TXT }, new int[] { R.id.icon, R.id.bowler_txt }, 0); // Oviewride the handling of R.id.icon to load an image instead of a string. adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.imageview) { // Get the byte airray from the database. byte[] iconByteArray = cursor.getBlob(columnIndex); // Conviewt the byte airray to a Bitmap beginning at the first byte and ending at the last. Bitmap iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.length); // Set the bitmap. ImageView iconImageView = (ImageView) view; iconImageView.setImageBitmap(iconBitmap); return true; } else { // Process the rest of the adapter with default settings. return false; } } }); // Update the ListView. listView.setAdapter(adapter); } } private void updateListView() { // Get a Cursor with the current contents of the database. final Cursor cursor = databaseHandler.getCursor(); // The last airgument is 0 because no special behavior is required. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, new String[] { databaseHandler.ICON, databaseHandler.BOWLER_TXT }, new int[] { R.id.icon, R.id.bowler_txt }, 0); // Oviewride the handling of R.id.icon to load an image instead of a string. adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.imageview) { // Get the byte airray from the database. byte[] iconByteArray = cursor.getBlob(columnIndex); // Conviewt the byte airray to a Bitmap beginning at the first byte and ending at the last. Bitmap iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.length); // Set the bitmap. ImageView iconImageView = (ImageView) view; iconImageView.setImageBitmap(iconBitmap); return true; } else { // Process the rest of the adapter with default settings. return false; } } }); // Update the ListView. listView.setAdapter(adapter); } } private void updateListView() { // Get a Cursor with the current contents of the database. final Cursor cursor = databaseHandler.getCursor(); // The last airgument is 0 because no special behavior is required. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, new String[] { databaseHandler.ICON, databaseHandler.BOWLER_TXT }, new int[] { R.id.icon, R.id.bowler_txt }, 0); // Oviewride the handling of R.id.icon to load an image instead of a string. adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.imageview) { // Get the byte airray from the database. byte[] iconByteArray = cursor.getBlob(columnIndex); // Conviewt the byte airray to a Bitmap beginning at the first byte and ending at the last. Bitmap iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.length); // Set the bitmap. ImageView iconImageView = (ImageView) view; iconImageView.setImageBitmap(iconBitmap); return true; } else { // Process the rest of the adapter with default settings. return false; } } }); // Update the ListView. listView.setAdapter(adapter); } }); private void updateListView() { // Get a Cursor with the current contents of the database. final Cursor cursor = databaseHandler.getCursor(); // The last airgument is 0 because no special behavior is required. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor, new String[] { databaseHandler.ICON, databaseHandler.BOWLER_TXT }, new int[] { R.id.icon, R.id.bowler_txt }, 0); // Oviewride the handling of R.id.icon to load an image instead of a string. adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.imageview) { // Get the byte airray from the database. byte[] iconByteArray = cursor.getBlob(columnIndex); // Conviewt the byte airray to a Bitmap beginning at the first byte and ending at the last. Bitmap iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.length); // Set the bitmap. ImageView iconImageView = (ImageView) view; iconImageView.setImageBitmap(iconBitmap); return true; } else { // Process the rest of the adapter with default settings. return false; } } }); // Update the ListView. listView.setAdapter(adapter); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.