Back to project page ExpandableListDemoApp.
The source code is released under:
MIT License
If you think the Android project ExpandableListDemoApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.frost.david.android.fragments; /*www . j a v a 2 s . co m*/ import android.app.Activity; import android.app.ListFragment; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class ItemListFragmentFragment extends ListFragment { private static final String ARG_LIST = "list"; private static final String ARG_NAME = "name"; private String[] mItems; private String name; private OnFragmentInteractionListener mListener; public static ItemListFragmentFragment newInstance(String name, String[] items) { ItemListFragmentFragment fragment = new ItemListFragmentFragment(); Bundle args = new Bundle(); args.putStringArray(ARG_LIST, items); args.putString(ARG_NAME, name); fragment.setArguments(args); return fragment; } public ItemListFragmentFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mItems = getArguments().getStringArray(ARG_LIST); name = getArguments().getString(ARG_NAME); } setListAdapter(new ArrayAdapter<String>( getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, mItems)); if (mListener != null) mListener.setTitle(name); } @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) { // mListener.setTitle(DummyContent.ITEMS.get(position).id); Toast.makeText(getActivity(), mItems[position], Toast.LENGTH_SHORT).show(); } } public interface OnFragmentInteractionListener { public void setTitle(String name); } }