Android Open Source - ExpandableListDemoApp Item List Fragment Fragment






From Project

Back to project page ExpandableListDemoApp.

License

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.

Java Source Code

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);
    }

}




Java Source Code List

de.frost.david.android.ApplicationTest.java
de.frost.david.android.MyActivity.java
de.frost.david.android.adapters.DrawerExpandableAdapter.java
de.frost.david.android.fragments.ItemListFragmentFragment.java
de.frost.david.android.fragments.NavigationDrawerFragment.java
de.frost.david.android.model.Category.java
de.frost.david.android.model.SubCategory.java