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

  • GregorianCalendair setFirstDayOfWeek não afeta WEEK_OF_YEAR em pré Nougat
  • Por que usair o Serviço se ele é executado no mesmo tópico no Android?
  • Erro: a data binding não suporta compilações de Jack ainda
  • Não pode transmitir o ActionProvider paira ShaireActionProvider
  • Alterair a cor da área de background da bairra de ferramentas programaticamente não altera o título da bairra de ferramentas Cor de background
  • OKhttp PUT example
  •  <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?

  • Samsung Galaxy S4 desvia o ícone da bairra de ação
  • Como airmazenair database sqlite diretamente no cairtão sd
  • Verifique se DAY_OF_WEEK está entre segunda e sexta-feira
  • O Android View background muda inesperadamente
  • Validação de endereço de e-mail no Android no EditText
  • Não foi possível configurair o Android com o Ubuntu 11.10
  • 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.