Android LiveView Loading Data

Source: Internet
Author: User

Set layout

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android = "Http://schemas.android.com/apk/res/android" android:layout_width= "match_parent" android:layout_height= "Match_ Parent "> <textview android:id=" @+id/itemstitle "android:layout_width=" Wrap_content "and        roid:layout_height= "Wrap_content" android:layout_gravity= "center_vertical" android:paddingleft= "10dip" android:paddingtop= "5dip" android:textcolor= "@color/gray_black" android:textsize= "18dip"/> <text View android:id= "@+id/itemstext" android:layout_width= "wrap_content" android:layout_height= "Wrap_cont        Ent "android:layout_below=" @+id/itemstitle "android:gravity=" left "android:paddingbottom=" 2dip " android:paddingleft= "10dip" android:textcolor= "@color/gray" android:textsize= "15dip"/></relativelay Out> 

Fetching data from a collection of maps

Get Data Intent Intent = getintent (); Bundle bundle = Intent.getextras (); Serializablemaplist serializablemaplist = (serializablemaplist) bundle.get ("Listdata"); maplist = Serializablemaplist.getmap ();  Populate data ListView Mlistview = (listview) Findviewbyid (R.id.listview);//Use custom Adaptermylistviewadapter Mylistviewadapter = new Mylistviewadapter (this, maplist,r.layout.list_items,new string[] {"RQSJ", "s", "F", "JLR"}, New Int[] {r.id.itemstitle,r.id.itemstext}); Mlistview.setadapter (Mylistviewadapter);

Custom Class Mylistviewadapter

Package Com.xjx.adapter;import Java.util.list;import Java.util.map;import android.content.context;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.widget.baseadapter;import android.widget.textview;/** * Copyright (c) All rights reserved * Name: Mylistviewad Apter * Description: ListView Custom Adapter Example * @author ZHAOQP * @date 2011-11-8 * @version */public class Mylistviewadapter extends Ba    seadapter{private Context Mcontext;    Single-line layout private int mresource; The data displayed in the list is private list<?    Extends Map<string,?>> Mdata;    The key in map is private string[] mfrom;       View's ID private int[] mTo; /** * Construction Method * @param context * @param data list @param the layout of the resource single line * @param the key in the from map * @para            ID of M to view */public Mylistviewadapter (context context, list<? extends Map<string,?>> data,     int resource, string[] from, int[] to) {Mcontext = context;    Mdata = data;     Mresource = resource;         Mfrom = from;    MTo = to;    } @Override public int getcount () {return mdata.size ();    } @Override public Object getItem (int position) {return mdata.get (position);    } @Override public long getitemid (int position) {return position;           } @Override public View getView (int position, view Convertview, ViewGroup parent) {final Viewholder holder; if (Convertview = = null) {//Use custom List_items as layout Convertview = Layoutinflater.from (mcontext          ). Inflate (Mresource, parent, false);  Use the number of reduced findview holder = new Viewholder ();  Holder.itemstitle = ((TextView) Convertview.findviewbyid (mto[0]));  Holder.itemstext = ((TextView) Convertview.findviewbyid (mto[1]));          Set tag Convertview.settag (holder);          }else{holder = (viewholder) convertview.gettag ();      }//Set Data final map<string,?> dataset = Mdata.get (position);    if (DataSet = = null) {return null;          }//Gets the row data final Object data1 = Dataset.get (mfrom[0]);          Final Object data2 = Dataset.get (mfrom[1]);          Final Object data3 = Dataset.get (mfrom[2]);          Final Object data4 = Dataset.get (mfrom[3]);          Set the data to view Holder.itemsTitle.setText (data1.tostring () + "" +data2.tostring () + ":" +data3.tostring ());          Holder.itemsText.setText (Data4.tostring ());    return convertview; }/** * Viewholder classes */static class Viewholder {TextView itemstitle; TextView Itemstext;}}

  

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.