изображение в виде списка из sqlite - PullRequest
2 голосов
/ 15 декабря 2011

Я пытаюсь заполнить представление списка изображениями из bbdd, я могу сделать все, но не отображать изображение, которое я думаю, потому что есть 2 xmls, один для представления списка и другой для каждой строки:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

<ListView  
android:id="@android:id/list"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/>
    </LinearLayout>

и row.xml, которые имеют представление изображения и текстовое представление

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/layoutEntrada" 
 android:paddingTop="4dip"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:paddingBottom="6dip"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="vertical">

 <LinearLayout

 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal">

     <ImageView
         android:id="@+id/imagenLugar"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginRight="6dip"
         android:src="@drawable/icon" />

 <TextView android:id="@+id/nombreLugar"
    android:textColor="#4B89E0" 
     android:layout_width="130dip"
     android:layout_height="40dip"
     android:textSize = "15dip"
     />

</LinearLayout>          

</LinearLayout>

В коде у меня есть 2 части, сначала я создаю свой простой simplecursoradapter для заполнения представления изображения и принципала активности.Вот адаптер

public class miAdapter extends SimpleCursorAdapter {
    Context context;




    public miAdapter(Context context2, int layout, Cursor fotosC,
            String[] deFoto, int[] aFoto) {
        super(context2, layout, fotosC, deFoto, aFoto);
    }




    public void setViewImage(ImageView v, Uri contentUri, Context contextoPath) {

            Bitmap bmImg = BitmapFactory.decodeFile("/sdcard/download/is.jpg");
            v.setImageBitmap(bmImg);



    }

Это растровое изображение, если попытаться, когда с одним изображением работает, я изменю этот код, добавив все мои изображения

А теперь основной код:

public class listatab extends ListActivity implements OnItemClickListener{  

    Context context;
    ListView listanombres;
    DataBaseHelper ayudabbdd;
    TextView texto;
    SimpleCursorAdapter lugaresNombre;
    miAdapter lugaresFoto;
    Cursor nombresC;
    Cursor fotosC;
    ListView listaview;
   ImageView imagenFoto;

  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);   
    setContentView(R.layout.listatab);
    context = getBaseContext();
    someCallback();

    ayudabbdd = new DataBaseHelper(this);           
    nombresC = (Cursor) ayudabbdd.getNombres();  
    fotosC = (Cursor)ayudabbdd.getImagenes();

    startManagingCursor(nombresC);
    startManagingCursor(fotosC);
    nombresC.moveToFirst();
    fotosC.moveToPosition(0);

    String[] deFoto = new String[]{DataBaseHelper.CFOTO};
    int[] aFoto = new int[]{R.id.imagenLugar};
    lugaresFoto = new miAdapter(this, R.layout.entrada_lista, fotosC, deFoto, aFoto);
    int longitudCursor = fotosC.getCount();


    for(int i=0; i<=longitudCursor-2;i++)
    {
        Context contextoo = getBaseContext();

        String fotoactual = fotosC.getString(1);
        lugaresFoto.setViewImage(imagenFoto, Uri.parse(fotoactual),contextoo);
        fotosC.moveToNext();

    }
    this.setListAdapter(lugaresFoto);


    String[] deNombre = new String[]{DataBaseHelper.CNOMBRE};
    int[] aNombre = new int[]{R.id.nombreLugar};
    lugaresNombre = new SimpleCursorAdapter(this, R.layout.entrada_lista, nombresC, deNombre, aNombre);
    setListAdapter(lugaresNombre);
    listaview= getListView();
    listaview.setOnItemClickListener(this);



  }


  private void someCallback() {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.entrada_lista, null);
      imagenFoto = (ImageView) ll.findViewById(R.id.imagenLugar);
      imagenFoto.setImageBitmap(BitmapFactory.decodeFile("/sdcard/download/is.jpg"));
  }

Это тоже проверенный код для попытки, если работать только с изображением, из-за этого я пишу строку las

      imagenFoto.setImageBitmap(BitmapFactory.decodeFile("/sdcard/download/is.jpg"));

Код отлично работает для заполнения представлений списка имен, но неИзображения Чтобы попробовать только с одним изображением, но он не показывался, я думаю, что я не объявляю ImageView из любого ряда правильно, но я не знаю, сделать это лучше.Извините за мой английский очень плохой.Пожалуйста, помогите!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...