Are you talking about android.widget.Adapter? Not at the moment. The problem is that most adapters use new() to create new views, which means that Guice isn't constructing the view instances, which means that it doesn't have an opportunity to do injection.
It might be an interesting experiment to come up with an adapter pattern that integrated with Guice, but no one has tried it yet to my knowledge.
Cheers,
Mike
--
http://about.me/michaelburton
On Jan 25, 2011, at 4:05 PM, thevery wrote:
> Is it possible to use @InjectView within adapter? Or maybe even with
> using convertView/viewHolder/itemViewType?
>
> --
> You received this message because you are subscribed to the Google Groups "roboguice" group.
> To post to this group, send email to robo...@googlegroups.com.
> To unsubscribe from this group, send email to roboguice+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/roboguice?hl=en.
>
2011/1/26 Michael Burton <mi...@niskala.org>:
2011/1/26 Donn Felker <do...@donnfelker.com>:
One obvious disadvantage with a RoboBaseAdapter is that it won't work with existing adapter classes. :( Perhaps we could supplement it with a provider or factory that any adapter could use to create a new injected view.
Adam has some experience with AssistedInject and adapters which may be relevant here. https://groups.google.com/d/msg/roboguice/Wtxd8YVQ9_A/pDs4-6_EZWwJ
--
http://about.me/michaelburton
Some simple implementation here:
https://gist.github.com/802366
In activity you should use something like
buttonList.setAdapter(new RoboBaseAdapterButton(this,
R.layout.list_item_button, Arrays.asList("button1",
"button2", "button3")));
Some remarks:
1) At the moment all it can do is @InjectView support inside adapter
using same technique as RoboActivity, but doesn't use ContextScope and
thus more 'coupled' with adapter and view parameters:
1.1) Unfortunately it isn't possible to use ViewMembersInjector from
ViewListener because findViewById is called explicitely on Activity
and it is not possible to call it on View, so scope can't be used
1.2) I'm not sure it is ok to 'link' directly to BaseAdapter and View
or it should be provided like AdapterScope or something like this.
1.3) 'Magic' binding preparation is done in the helper method init()
in constructor to be easier reusable of multiple constructors.
1.3.1) But in RoboGuice you guys usually duplicate initialization
calls, not separate (e.g. setContentView in RoboListActivity).
1.3.2) It is ok to get LayoutInflater explicitely (inflater =
LayoutInflater.from(context);) or I should better inject it?
1.3.3) I don't actually like very much prepareFields method call here
but it seems quite impossible to use/reuse injectMembers or
requestStaticInjection because of the same reasons as 1.1 AND because
it should be cached for multiple calls (and ContextScope
implementation is probably can't handle this correctly)
2) All binding 'magic' actually happens inside BaseAdaper.getView().
I'm not 100% sure it is the beast place but it makes usage quite
simple.
3) ViewHolder pattern is not implemented yet - I haven't found best
implementation way yet :( Probably should be dynamically created based
on @InjectView fields
4) No support for getViewTypeCount - actually this makes 3) even more
tricky - you need to have some layoutId<->ViewHolder mapping which
requires some not so easy @InjectView hacks - like creating
@InjectViewInLayout(R.id.view_buton, R.layout.layout_buton)
5) Not a question for the current implementation, but some idea:
probabaly provide some RoboArrayAdapter with BindItemToView interface
method.
P.S Please excuse me for so much question for the first time but I'm
not quite familiar with RoboGuice internals and I would appreciate if
you can comment some of my questions.
Ildar
2011/1/26 Michael Burton <mi...@niskala.org>:
I'll make some multiviewType-ready implementation and post update
here. For IViewFinder abstraction I should probably wait first for
your or Michael implementation since you understand that 'magic'
better.
Ildar
2011/1/30 Adam Tybor <adam....@gmail.com>:
Seems like this shouldn't be too hard to fix, though. We could inject a static Provider<Injector> into BaseAdapter, then use it to get an injector and injector.injectMembers() on the view. This would leverage the existing ViewListener as well as perform all the other types of injection.
Mike
--
http://about.me/michaelburton
void bind(MyType myType) {
}
}
with different holders for different view types
2011/1/30 Adam Tybor <adam....@gmail.com>: