我试图使用来自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具有图像视图和textview
<?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>
在代码中我有两部分,首先我创建自己的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"));
}
这也是一个尝试过的代码,如果只使用图像,因为我写了拉斯行
imagenFoto.setImageBitmap(BitmapFactory.decodeFile("/sdcard/download/is.jpg"));
代码可以正常填充名称列表视图,但不能填充图像 要尝试只有一个图像,但没有显示他,我想我没有正确地从任何行声明ImageView但我不知道让这更好。 抱歉,我的英语很差。 请帮助!