/* * Copyright (C) 2012-2016 The Android Money Manager Ex Project Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.money.manager.ex.investment; import android.app.Activity; import android.os.Bundle; import android.app.ListFragment; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import com.money.manager.ex.common.BaseListFragment; import com.money.manager.ex.investment.dummy.DummyContent; /** * A fragment representing a list of Items. * <p/> * <p/> * Activities containing this fragment MUST implement the {@link OnFragmentInteractionListener} * interface. */ public class InvestmentItemsListFragment extends BaseListFragment { private OnFragmentInteractionListener mListener; // TODO: Rename and change types of parameters public static InvestmentItemsListFragment newInstance(String param1, String param2) { InvestmentItemsListFragment fragment = new InvestmentItemsListFragment(); Bundle args = new Bundle(); // args.putString(ARG_PARAM1, param1); // args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } /** * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */ public InvestmentItemsListFragment() { } @Override public String getSubTitle() { // todo: show the account name here. return null; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { // mParam1 = getArguments().getString(ARG_PARAM1); // mParam2 = getArguments().getString(ARG_PARAM2); } // TODO: Change Adapter to display your content setListAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS)); } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mListener = (OnFragmentInteractionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener"); } } @Override public void onDetach() { super.onDetach(); mListener = null; } @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); if (null != mListener) { // Notify the active callbacks interface (the activity, if the // fragment is attached to one) that an item has been selected. mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id); } } /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated * to the activity and potentially other fragments contained in that * activity. * <p/> * See the Android Training lesson <a href= * "http://developer.android.com/training/basics/fragments/communicating.html" * >Communicating with Other Fragments</a> for more information. */ public interface OnFragmentInteractionListener { // TODO: Update argument type and name public void onFragmentInteraction(String id); } }