La clase del Adapter
Código java:
Ver original
package com.xxx; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; public class AdapterServices extends ArrayAdapter <String> { private final Activity Ct; private final int[] Img; private final int res; { super(c, s, d); /* */ this.Ct = c; this.Text = d; /* El tamaño de Text, debería */ this.Img = i; /* ser de igual al de Img. */ this.res = s; } @Override { View v; if ((v = convertView) == null) { LayoutInflater i = (LayoutInflater) Ct .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); v = i.inflate(this.res, null); } TextView t = (TextView) v.findViewById(R.id.ImageServicesListView); t.setText(this.Text[position]); ImageView i = (ImageView) v.findViewById(R.id.TextServicesListView); i.setImageResource(this.Img[position]); return v; } }
Main
Código Java:
Ver original
package com.xxx; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); int[] i = new int[] { R.drawable.ic_launcher, R.drawable.ic_launcher }; AdapterServices a = new AdapterServices(this, s, i, R.layout.serviceslistview); l.setAdapter(a); } }
Y los respectivos XML que meteré en el ListView
Código XML:
Ver original
<?xml version = "1.0" encoding = "UTF-8" ?> <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:background = "#5ba3d5" > <ImageView android:id = "@+id/ImageServicesListView" android:layout_width = "60dp" android:layout_height = "60dp" /> <TextView android:id = "@+id/TextServicesListView" android:layout_width = "60dp" android:layout_height = "60dp" /> </LinearLayout>
Y el XML del main
Código XML:
Ver original
<?xml version = "1.0" encoding = "utf-8" ?> <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:background = "#5ba3d5" > <ListView android:id = "@+id/list_services" android:layout_width = "fill_parent" android:layout_height = "fill_parent" /> </LinearLayout>
Espero que me puedan ayudar, un saludos, muchas gracias.
---
Resolví el problema, estaba aquí.
Código Java:
Ver original
TextView t = (TextView) v.findViewById(R.id.ImageServicesListView); t.setText(this.Text[position]); ImageView i = (ImageView) v.findViewById(R.id.TextServicesListView); i.setImageResource(this.Img[position]);
Estaba usando el ID del TextView en el ImageView y viceversa. Muchas gracias igual.