externes Bild via URL einbinden

  • 1 Antworten
  • Letztes Antwortdatum
K

KimPink

Neues Mitglied
0
Hallo zusammen,
ich möchte ein Bild in mein App bekommen, was später austauschbar sein soll und deshalb dies via URL geschehen soll.
Code:
[COLOR=darkred]public[/COLOR] [COLOR=darkred]class[/COLOR] Dashboard [COLOR=darkred]extends[/COLOR] Activity {

	[COLOR=darkred]private[/COLOR] ImageView mImageView;

	@Override
	[COLOR=darkred]protected[/COLOR] [COLOR=darkred]void[/COLOR] onCreate(Bundle savedInstanceState) {
	
		[COLOR=darkred]super[/COLOR].onCreate(savedInstanceState);
		setContentView(R.layout.dashboard);
		mImageView=(ImageView) findViewById(R.id.iv_hintergrund);
	}

	@Override
	[COLOR=darkred]protected[/COLOR] [COLOR=darkred]void[/COLOR] onStart() {
		
		[COLOR=darkred]super[/COLOR].onStart();
		bildLaden();
	}

	[COLOR=darkred]private[/COLOR] [COLOR=darkred]void[/COLOR] bildLaden() {
		[COLOR=darkviolet]String[/COLOR] urlString=[COLOR=red]"http://xyonline.de/wp-content/uploads/2010/08/android.gif"[/COLOR];
		[COLOR=darkred]try[/COLOR] {
			mImageView.setImageDrawable(
			Drawable.createFromStream((InputStream)
					[COLOR=darkred]new[/COLOR] URL(urlString).getContent(), [COLOR=red]"startseite"[/COLOR])		
		);
		} [COLOR=darkred]catch[/COLOR] (MalformedURLException e) {
		e.printStackTrace();
		} [COLOR=darkred]catch[/COLOR] (IOException e) {
			e.printStackTrace();
		}
		
	}

}
Code:
[COLOR=blue]<?[COLOR=darkred]xml[/COLOR] [COLOR=darkred]version=[COLOR=red]"1.0"[/COLOR][/COLOR] encoding=[COLOR=red]"utf-8"[/COLOR]?>[/COLOR]
<LinearLayout
  xmlns:android=[COLOR=red]"http://schemas.android.com/apk/res/android"[/COLOR]
  android:layout_width=[COLOR=red]"fill_parent"[/COLOR]
  android:layout_height=[COLOR=red]"fill_parent"[/COLOR]
  android:background=[COLOR=red]"@color/weiss"[/COLOR]
  android:orientation=[COLOR=red]"vertical"[/COLOR]
  android:padding=[COLOR=red]"10dip"[/COLOR]>
  <ImageView
  android:layout_width=[COLOR=red]"fill_parent"[/COLOR]
  android:layout_height=[COLOR=red]"wrap_content"[/COLOR]
  android:id=[COLOR=red]"@+id/iv_hintergrund"[/COLOR]
  android:layout_weight=[COLOR=red]"1"[/COLOR]
  />
  <Button
  android:layout_width=[COLOR=red]"fill_parent"[/COLOR]
  android:layout_height=[COLOR=red]"wrap_content"[/COLOR]
  android:text=[COLOR=red]"test"[/COLOR]
  />
  


[COLOR=blue]</[COLOR=darkred]LinearLayout[/COLOR]>[/COLOR]


Hab das Gefühl, dass ich das ganz falsch angegangen bin. Habt ihr vielleicht nen Codeschnipsel oder eine Idee wie das ganz einfach funktioniert, oder schwer ABER trotzdem funktioniert. Mit meinem Latein bin ich am Ende.
Vielen Dank schon mal :thumbsup:
 
Hallo,

hilft Dir das hier weiter?

Gruß
Bobert
 
Zurück
Oben Unten