Android: ListView with complex data model -
I want to map an array of "complex" data in a ListView. In a very simple way, my data model will look something like this:
class ListPlacesValues {String idObject; String name; String City; String country; ArrayList & LT; String & gt; Classification; Double distance_type; DistanceUnit distance_unit; [... more stuff ...]}
I know that I can convert my complex data into a hashlist and then just use SimpleAdapter:
Simple Adapter M Adapter = New Simple Adapter (This, Hashlist, R.Let.Place_LitTimem, New String [] {"Name", "City", "Country"}, New Ent [] {R} .d.am, RID city, R. Dendentry});
However, I will use my data model directly, but I do not know where and how to start, so that in the end I can do something like this:
ArrayList & LT; ListPlacesValues & gt; Value = meet (); MyAdapter mAdapter = New MyAdapter (this, value, r layout.plus_lititcom, listplaces values {values.name, values.city, values.country}, new int [] {rdid.name, rdct ., R. Id.country});
Solution: I found this Android API sample (), which was really helpful.
You can extend ArrayAdapter. Here is an example of a code for you - In this example - SearchItem has some custom POJOs, in order for you to get a line, you must override the GetView () method to create your row and then the values based on the list of items and current status Populing
class SearchItemsAdapter ArrayAdapter and lt; SearchItem & gt; {Reference of activity; & Lt; SearchItem & gt; item; Search header header; @SuppressWarnings ("uncheck") Public SearchItemsAdapter (last activity reference, last map & lt; SearchHeader, list & amp; lt; SearchItem & gt; & gt; results) {super (references, R.Lit.Items, (list) ((Object []) result.values () .toArray ()) [0]); This.context = context; This.header = result.keySet (). Iterator () Next (); This.items = result.get (this.header); } @ Override Public View getView (last integer status, last view, see the convert group, final view group origin) {Final View View = this.context.getLayoutInflater (). Flood (R. layout.itim, empty); Last Search item item = this.items.get (status); (TextView) view.findViewById (R.id.jt)). SetText (item.jt); (TextView) view.findViewById (R.id.dp)). SetText (item.dp); (TextView) viewfindvibid (RIDCN) settext (item CN); (TextView) view.findViewById (R.id.loc)). SetText (item.loc.name); Last TextView body = ((TextView) view.Fund Veebid (RIDE)); Body.setText (item.e); Body.setTag (item.src [0]); (TextView) viewfindvibid (RDCRC) settext (item SRC [1]); Return view; }}
Comments
Post a Comment