android - Displaying custom objects in ArrayAdapter - the easy way? -
i trying display list of bluetooth devices in arrayadapter
, , want override default functionality of adapter show objects tostring()
. know there solutions extend getview(...)
method, feel over-complicating things. want override how string display built. bluetooth devices using getname()
instead of tostring()
.
so i've created custom arrayadapter below, , ideally have method getdisplaystring(t value)
public class myarrayadapter extends arrayadapter<bluetoothdevice> { ... @override //i wish existed protected string getdisplaystring(bluetoothdevice b) { return b.getname(); } ... }
altering behavior of getview
doesn't have complicated.
madapter = new arrayadapter<mytype>(this, r.layout.listitem, new arraylist<mytype>()) { @override public view getview(int position, view convertview, viewgroup parent) { textview view = (textview) super.getview(position, convertview, parent); // replace text own view.settext(getitem(position).getname()); return view; } };
this has disadvantage of setting view's text twice (once in super.getview
, once in override) above, doesn't cost much. alternative create view using inflater if convertview
isn't there.
Comments
Post a Comment