1 package ${packageName};
3 import android.app.Activity;
4 import android.os.Bundle;
5 <#if switchGrid == true>
6 import android${SupportPackage}.app.Fragment;
7 import android.view.LayoutInflater;
9 import android${SupportPackage}.app.ListFragment;
11 import android.view.View;
12 <#if switchGrid == true>
13 import android.view.ViewGroup;
14 import android.widget.AbsListView;
15 import android.widget.AdapterView;
17 import android.widget.ArrayAdapter;
18 <#if switchGrid == true>
19 import android.widget.ListAdapter;
20 import android.widget.TextView;
22 import android.widget.ListView;
24 <#if applicationPackage??>import ${applicationPackage}.R;</#if>
26 import ${packageName}.dummy.DummyContent;
29 * A fragment representing a list of Items.
31 <#if switchGrid == true>
32 * Large screen devices (such as tablets) are supported by replacing the ListView
36 * Activities containing this fragment MUST implement the {@link Callbacks}
39 <#if switchGrid == true>
40 public class ${className} extends Fragment implements AbsListView.OnItemClickListener {
42 public class ${className} extends ListFragment {
46 // TODO: Rename parameter arguments, choose names that match
47 // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
48 private static final String ARG_PARAM1 = "param1";
49 private static final String ARG_PARAM2 = "param2";
51 // TODO: Rename and change types of parameters
52 private String mParam1;
53 private String mParam2;
56 private OnFragmentInteractionListener mListener;
58 <#if switchGrid == true>
60 * The fragment's ListView/GridView.
62 private AbsListView mListView;
65 * The Adapter which will be used to populate the ListView/GridView with
68 private ListAdapter mAdapter;
72 // TODO: Rename and change types of parameters
73 public static ${className} newInstance(String param1, String param2) {
74 ${className} fragment = new ${className}();
75 Bundle args = new Bundle();
76 args.putString(ARG_PARAM1, param1);
77 args.putString(ARG_PARAM2, param2);
78 fragment.setArguments(args);
84 * Mandatory empty constructor for the fragment manager to instantiate the
85 * fragment (e.g. upon screen orientation changes).
87 public ${className}() {
91 public void onCreate(Bundle savedInstanceState) {
92 super.onCreate(savedInstanceState);
95 if (getArguments() != null) {
96 mParam1 = getArguments().getString(ARG_PARAM1);
97 mParam2 = getArguments().getString(ARG_PARAM2);
101 // TODO: Change Adapter to display your content
102 <#if switchGrid == true>
103 mAdapter = new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
104 android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS);
106 setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
107 android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS));
111 <#if switchGrid == true>
113 public View onCreateView(LayoutInflater inflater, ViewGroup container,
114 Bundle savedInstanceState) {
115 View view = inflater.inflate(R.layout.${fragment_layout}, container, false);
118 mListView = (AbsListView) view.findViewById(android.R.id.list);
119 ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
121 // Set OnItemClickListener so we can be notified on item clicks
122 mListView.setOnItemClickListener(this);
129 public void onAttach(Activity activity) {
130 super.onAttach(activity);
132 mListener = (OnFragmentInteractionListener) activity;
133 } catch (ClassCastException e) {
134 throw new ClassCastException(activity.toString()
135 + " must implement OnFragmentInteractionListener");
140 public void onDetach() {
145 <#if switchGrid == true>
147 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
148 if (null != mListener) {
149 // Notify the active callbacks interface (the activity, if the
150 // fragment is attached to one) that an item has been selected.
151 mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
156 * The default content for this Fragment has a TextView that is shown when
157 * the list is empty. If you would like to change the text, call this method
158 * to supply the text it should use.
160 public void setEmptyText(CharSequence emptyText) {
161 View emptyView = mListView.getEmptyView();
163 if (emptyText instanceof TextView) {
164 ((TextView) emptyView).setText(emptyText);
169 public void onListItemClick(ListView l, View v, int position, long id) {
170 super.onListItemClick(l, v, position, id);
172 if (null != mListener) {
173 // Notify the active callbacks interface (the activity, if the
174 // fragment is attached to one) that an item has been selected.
175 mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
181 * This interface must be implemented by activities that contain this
182 * fragment to allow an interaction in this fragment to be communicated
183 * to the activity and potentially other fragments contained in that
186 * See the Android Training lesson <a href=
187 * "http://developer.android.com/training/basics/fragments/communicating.html"
188 * >Communicating with Other Fragments</a> for more information.
190 public interface OnFragmentInteractionListener {
191 // TODO: Update argument type and name
192 public void onFragmentInteraction(String id);