Use listview in Android to display bitmap downloaded over the network

Source: Internet
Author: User
// Processing Method for displaying the downloaded data from the network in listview. The focus is to display the processing of Bitmap problems and directly paste the code for future reference. Public class viewdiannao extends activity {private linearlayout mylistlayout; // declare the linearlayout type variable private listview triplistview; // declare the listview type variable private progressdialog mydialog; // declare the progressdialog type variable private list <goods> goodslist; // declare the list type variable @ overrideprotected void oncreate (bundle savedinstancestate) {// todo auto-generated method stubsuper. oncreate (savedinstancestate); this. setcontentview (R. layou T. viewdiannao); // load viewtuijian. XML resource file mylistlayout = (linearlayout) This. findviewbyid (R. id. triplist); // get the linearlayouttriplistview = new listview (this) in the resource file; // create a listview object // create a linearlayout. layoutparams type object linearlayout. layoutparams triplistviewparam = new linearlayout. layoutparams (linearlayout. layoutparams. fill_parent, linearlayout. layoutparams. fill_parent); triplistview. setcachecolorhint (color. wh ITE); mylistlayout. addview (triplistview, triplistviewparam); // Add triplistview to the mylistlayout layout getgoodslist (); // read the product list triplistview. setonitemclicklistener (New onitemclicklistener () {// Click Event @ overridepublic void onitemclick (adapterview <?> Arg0, view arg1, int position, long ID) {// todo auto-generated method stubgoods thegood = goodslist. get (position); // obtain the intent it = new intent () selected item in the current list; // create the intent object bundle = new bundle (); // create the bundle object it. setclass (viewdiannao. this, shangpindetailview. class); bundle. putserializable ("goodobj", (serializable) thegood); it. putextras (bundle); startactivity (IT) ;}}); // read the product list data private void getgoodslist () {mydialog = progressdialog. show (viewdiannao. this, "Please wait... "," data retrieval... ", true); New thread () {public void run () {try {goodslist = new connectweb (). gettypelist (3); // obtain the item list of the computer office category. 3 indicates that the category is Computer Office message m = new message (); listhandler. sendmessage (m);} catch (exception e) {e. printstacktrace ();} finally {mydialog. dismiss ();}}}. start ();} handler listhandler = new handler () {public void handlemessage (Message MSG) {If (goodslist. size () = 0) {return;} showgoodslist (); // fill book list adapter }};/*** fill book list adapter */Public void showgoodslist () {simpleadapter adapter = new simpleadapter (this, gettriplist (), R. layout. tuijianrow, new string [] {"IMG", "name", "money", "zhe"}, new int [] {R. id. tripimg, R. id. triptitle, R. id. tripsegname, R. id. tripprov}); triplistview. setadapter (adapter); // Add the adapter adapteradapter for triplistview. setviewbinder (New viewbinder () {public Boolean setviewvalue (view arg0, object arg1, string textrepresentation) {If (arg0 instanceof imageview) & (arg1 instanceof Bitmap )) {imageview = (imageview) arg0; Bitmap bitmap = (Bitmap) arg1; imageview. setimagebitmap (Bitmap); Return true ;}else {return false ;}});} public list <Map <string, object >>gettriplist () {list <Map <string, object> List = new arraylist <Map <string, Object> (); For (INT I = 0; I <goodslist. size (); I + = 1) {Map <string, Object> map = new hashmap <string, Object> (); goods Goods = goodslist. get (I); try {URL picurl = new URL (goods. getdir () + "/" + goods. getpic (); bitmap pngbm = bitmapfactory. decodestream (picurl. openstream (); map. put ("IMG", pngbm);} catch (exception e) {e. printstacktrace ();} map. put ("name", "Product Name:" + goods. getbrand (); map. put ("money", "product price:" + "$" + goods. getprice (); map. put ("zhe", "commodity discount:" + goods. getdiscount (); list. add (MAP) ;}return list ;}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.