Si tengo 20 imagenes que mostrar en cuadros de dialogo… ¿tengo qué crear 20 layouts?
Publicado por Carlos (1 intervención) el 08/09/2020 20:45:11
Tengo 20 botones, al darle clic a cada botón se muestra un cuadro de dialogo con una imagen; cree un layout por cada imagen (20 imagenes, 20 layout).
Quisiera saber si es posible crear un solo layout con todas las imágenes, porque intente hacerlo con un solo layout pero, me marca un error.
.xml (SOLO PONGO DOS IMAGEVIEW PARA NO HACER TAN LARGO EL TEXTO AQUI)
botones.java
El error que me marca es el siguiente:
android.content.res.Resources$NotFoundException: Resource ID #0x7f0800fe type #0x12 is not valid
Quisiera saber si es posible crear un solo layout con todas las imágenes, porque intente hacerlo con un solo layout pero, me marca un error.
.xml (SOLO PONGO DOS IMAGEVIEW PARA NO HACER TAN LARGO EL TEXTO AQUI)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img1"
android:layout_centerInParent="true"
/>
<ImageView
android:id="@+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img2"
android:layout_centerInParent="true"
/>
</RelativeLayout>
botones.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Override
@SuppressLint("ResourceType")
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnImg1:
LayoutInflater imagen = LayoutInflater.from(Botones.this);
final View vista = imagen.inflate(R.id.img1, null);
AlertDialog.Builder alerta = new AlertDialog.Builder(Botones.this);
alerta.setCancelable(true);
dialog = alerta.create();
dialog.setView(vista);
dialog.show();
break;
}
}
El error que me marca es el siguiente:
android.content.res.Resources$NotFoundException: Resource ID #0x7f0800fe type #0x12 is not valid
Valora esta pregunta


0