Hi,

I got my ListView which shows one ImageView and two TextViews in every
row.

Now I want to load the images NOT from my ressources (as in many
examples) but from the internet.

Somehow this doesnt work with the SimpleAdapter. Is this a bug?

Here comes my code:

---------------------------------------------------------------------------

MEINUNGEN.XML:

<?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="@drawable/bg">

<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:cacheColorHint="#00000000"
android:divider="@drawable/divider" android:dividerHeight="1px"/>

</LinearLayout>

---------------------------------------------------------------------------

MEINUNGEN_LIST_ROW.XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" android:paddingTop="3dip"
android:paddingBottom="3dip" android:paddingLeft="3dip">

<ImageView android:id="@+id/icon" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/wolfgangroth" />

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

<TextView android:id="@+id/name" android:text="Thomas Öchsner"
android:textSize="10px" android:gravity="center_vertical"
android:paddingLeft="6dip" android:paddingTop="6dip"
android:textColor="#cccccc" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<TextView android:id="@+id/content" android:text="Dämpfer für von der
Leyen"
android:textSize="16px" android:gravity="center_vertical"
android:paddingLeft="6dip" android:paddingTop="6dip"
android:textColor="#eeeeee" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

</LinearLayout>

---------------------------------------------------------------------------

public class MeinungenListActivity extends ListActivity {

private static final String ICON = "icon";
private static final String NAME = "name";
private static final String CONTENT = "content";
private static final String INTENT = "intent";
private static final String[] PARAM = { ICON, NAME, CONTENT };

private List<Map<String, Object>> list = new ArrayList<Map<String,
Object>>();

public void onCreate(Bundle icicle) {
super.onCreate(icicle);

setContentView(R.layout.meinungen);

addItem(list, R.drawable.thomasoechsner, "Thomas Öchsner",
"Dämpfer für von der Leyen", new Intent(this,
MeinungenListActivity.class));

addItem(list, R.drawable.marcbeise, "Marc Beise",
"Die Banker ducken sich schon wieder weg", new Intent(this,
MeinungenListActivity.class));

addItem(list, R.drawable.wolfgangroth, "Wolfgang Roth",
"Röttgen setzt auf Angriff", new Intent(this,
MeinungenListActivity.class));

addItem(list, R.drawable.charlottefrank, "Charlotte Frank",
"Sorge um die Vorsorge", new Intent(this,
MeinungenListActivity.class));

SimpleAdapter notes = new SimpleAdapter(this, list,
R.layout.meinungen_list_row, PARAM, new int[] { R.id.icon, R.id.name,
R.id.content });
setListAdapter(notes);
}

public void addItem(List<Map<String, Object>> data, int icon, String
name, String content, Intent intent) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(ICON, icon);
map.put(NAME, name);
map.put(CONTENT, content);
map.put(INTENT, intent);
data.add(map);
}

---------------------------------------------------------------------------

THIS CODE IS THE PROBLEM (please look at "here_comes_it"):

public void addItem(List<Map<String, Object>> data, Bitmap
here_comes_it, String name, String content, Intent intent) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(ICON, here_comes_it);
map.put(NAME, name);
map.put(CONTENT, content);
map.put(INTENT, intent);
data.add(map);
}


try {
URL aURL = new URL("http://www.anddev.org/images/avatars/
6748766294aa15a585d1fd.jpg");
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
Bitmap here_comes_it = BitmapFactory.decodeStream(is);
is.close();

addItem(list, here_comes_it, "Daniela Kuhr", "Angst vor der
Genknolle", new Intent(this, MeinungenListActivity.class));
} catch (Exception e) {
e.printStackTrace();
}

---------------------------------------------------------------------------

do you have any suggestions to use bitmaps with listview and
simpleadapter?

thanks !

greetings,
marco

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to