I’m using Guice (Roboguice v2 to be exact with Guice v3) and I’m a bit new to it.
I have a singleton..
@Singleton
Accounts
{
public Account[] getAllAccounts()
{
// Stuff
}
}
And I also have a class which needs access to the above in its constructor..
public class AccountListAdapter extends ArrayAdapter<Account>
{
public AccountListAdapter(Context c)
{
super(c, R.layout.account_list_row, R.id.accountName, accounts.getAllAccounts());
}
...
}
How can I gain access to the Accounts singleton above used as the last parameter of the super() call? As the constructor will execute before any instance variables are created.
Thanks!
You could handle this two ways.
First you could inject the Adapter directly into your Activity. This will include the current Context as well as the singelton:
keep in mind you need to add the following annotation:
Second, you could construct the object yourself during the onCreate():
You may have to extend the Roboguice ListActivity instead of the RoboActivity to use the ListActivity successfully. Let me know if this works for you.