android - How can I add an ImageView to an ArrayAdapter? -
how add imageviews arrayadapter show them in listview? tried making adapter arrayadapter<imageview>
, didn't work. here's code:
package com.example.picscroller; import java.util.arraylist; import java.util.list; import android.app.activity; import android.os.bundle; import android.view.menu; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.imageview; import android.widget.listview; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview list = (listview)findviewbyid(r.id.list); arrayadapter<imageview> myarrayadapter = new arrayadapter<imageview>(this, android.r.layout.simple_list_item_1); list.setadapter(myarrayadapter); list.settextfilterenabled(true); final button addbutton = (button) findviewbyid(r.id.addbutton); final button removebutton = (button) findviewbyid(r.id.removebutton); addbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub } }); imageview droid = new imageview(this); droid.setimageresource(r.drawable.droid); myarrayadapter.add(droid); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
...and here's happened:
understand why happened how can make work (how add imageview listview/arrayadapter?)
thanks.
edit okay, androiduniversalimageloader might useful how use @rsenapps
instead of doing yourself, highly recommend using https://github.com/nostra13/android-universal-image-loader, make life lot easier , nicer too!
Comments
Post a Comment