i tring load images and texts to a ListView using a arrayAdapter custom but the load image fail
here are my arrayAdapter
public class CustomAdapter extends ArrayAdapter<Post> {
private ImageTask image;
public CustomAdapter(Context context, ArrayList<Post> posts) {
super(context, 0, posts);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
Post post = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.post_list, parent, false);
}
// Lookup view for data population
TextView tituloView = (TextView) convertView.findViewById(R.id.titulo);
TextView subtituloView = (TextView) convertView.findViewById(R.id.subTitulo);
ImageView fotoView = (ImageView) convertView.findViewById(R.id.imageView);
TextView textoView = (TextView) convertView.findViewById(R.id.texto);
// Populate the data into the template view using the data object
tituloView.setText(post.post_titulo);
subtituloView.setText(post.post_sub_titulo);
//this like idk if are the way corret for load the image into ViewImage specific
new ImageTask(fotoView).execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
textoView.setText(post.post_texto);
// Return the completed view to render on screen
return convertView;
}
}
here a ImageTask image
public class ImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public ImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
and here the call from MainActivity
// Create the adapter to convert the array to views
CustomAdapter adapter = new CustomAdapter(this, arrayOfPost);
// Attach the adapter to a ListView
ListView listView = (ListView) findViewById(R.id.lvUsers);
listView.setAdapter(adapter);
the arrayOfPost is coming of a parse jonson to a ArrayList and links images is contained there, but in this example i using images from google developer
and the xml used by array adapter here
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/subTitulo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/texto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
any know which are my wrong and how i should to do for load images? i dont right if is the way corret for load the image in the specific ViewImage //this lines are in fist class posted
new ImageTask(fotoView).execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");