public static final String FRAGMENT_TAG = "account_list_fragment";
- private AccountFragmentListener mListener;
private List<Account> mAccounts; // List of accounts displayed in the spinner
private ListView mListView; // ListView used to show the bureaux of the currently selected account
private AccountListAdapter mAccountListAdapter;
mAccounts = new ArrayList<>();
}
- @Override public void onAttach(Context context) {
- super.onAttach(context);
-
- // Activities containing this fragment must implement its callbacks.
- if (!(context instanceof AccountFragmentListener))
- throw new IllegalStateException("Activity must implement AccountFragmentListener.");
-
- mListener = (AccountFragmentListener) context;
- }
-
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View content = inflater.inflate(R.layout.account_list_fragment, container, false);
View footerView = inflater.inflate(R.layout.account_list_fragment_footer, mListView, false);
footerView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
- if (mListener != null)
- mListener.onCreateAccountInvoked();
+ ((AccountFragmentListener) getActivity()).onCreateAccountInvoked();
}
});
mListView.addFooterView(footerView, null, false);
// <editor-fold desc="OnItemClickListener">
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-
- if (mListener != null)
- mListener.onAccountSelected(mAccounts.get(position));
+ ((AccountFragmentListener) getActivity()).onAccountSelected(mAccounts.get(position));
}
// </editor-fold desc="OnItemClickListener">