Use Android annotations in custom dialog class

I am using android androids, I am trying to annotate this class in order to save the value in the general preferences class (annotated) using @pref. I managed to find a job with an intention and a broadcast receiver, however this is not ideal, and now when I want to get the value from the general preferences in this class to show how the default element selected in spinner, it starts to smell my code.

Is there a way to annotate this class?

public class SelectNewsFeedDialog extends Dialog { private Context context; private Button confirmButton; private Spinner spinnerTeams; public SelectNewsFeedDialog(final Context context, ArrayList<Team> listTeams) { super(context,R.style.cust_dialog); this.context = context; setContentView(R.layout.dialog_choose_news_feed); spinnerTeams = (Spinner) findViewById(R.id.dialog_news_feed_spinner_teams); confirmButton = (Button) findViewById(R.id.dialog_news_feed_button_confirm); confirmButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Team team = (Team)spinnerTeams.getSelectedItem(); Intent intent = new Intent(context, IntentCenter_.class); intent.putExtra(context.getString(R.string.extra_update_team_news_feed), team.url.toString()); intent.setAction(context.getString(R.string.action_update_team_news_feed)); context.sendBroadcast(intent); dismiss(); } }); SpinnerTeamsAdapter adapter = new SpinnerTeamsAdapter(context, listTeams); spinnerTeams.setAdapter(adapter); } } 
+7
android android annotations
source share
1 answer

We currently have no comments for Dialog classes. You can use @EBean to do this, but the compiler yells about missing constructors.

The solution is to use DialogFragment instead of Dialog and annotate this class with @EFragment . The following code should work:

 @EFragment(R.layout.dialog_choose_news_feed) public class SelectNewsFeedDialog extends DialogFragment { @ViewById Button confirmButton; @ViewById Spinner spinnerTeams; @Extra List<Team> listTeams; @Click public void confirmButtonClicked() { Team team = (Team) spinnerTeams.getSelectedItem(); Intent intent = new Intent(context, IntentCenter_.class); intent.putExtra(context.getString(R.string.extra_update_team_news_feed), team.url.toString()); intent.setAction(context.getString(R.string.action_update_team_news_feed)); context.sendBroadcast(intent); dismiss(); } @AfterViews public void init() { SpinnerTeamsAdapter adapter = new SpinnerTeamsAdapter(getActivity(), listTeams); spinnerTeams.setAdapter(adapter); } } 

However, using @Extra on a list is not a good idea. You should: * use the list of identifiers annotated with @Extra * or, use the setter and pass this list to your adapter after the dialog has been initialized.

Hope this helps

+10
source share

All Articles