Android: Custom Arrayadapter(s) For Different Custom Objects
I have a number of custom objects that are significantly different from each other. These objects are stored in different lists and are to be displayed in different ListViews. Beca
Solution 1:
You can define your adapter like this:
publicclassMyArrayAdapter<T> extendsArrayAdapter<T>
{
HashMap<T, Integer> mIdMap = new HashMap<T, Integer>();
publicMyArrayAdapter(Context context, int textViewResourceId, List<T> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
}
Solution 2:
Probably, you want to use a BaseAdapter
. And in the getView()
of that adapter, check for the instanceof
of the object, do things accordingly.
Solution 3:
public interace SomeInterface
{
publicStringgetString();
}
publicclassclassAimplementsSomeInterface
{
...
@OverridepublicStringgetString()
{
return"blabla";
}
}
publicclassclassBimplementsSomeInterface
{
...
@OverridepublicStringgetString()
{
return"whatever";
}
}
publicclassInterfaceAdapterextendsArrayAdapter<SomeInterface>
{
publicInterfaceAdapter (Context context, int resource, List<SomeInterface> objects) {...}
}
Post a Comment for "Android: Custom Arrayadapter(s) For Different Custom Objects"