Android Open Source - FishApp Vendor Product List Fragment






From Project

Back to project page FishApp.

License

The source code is released under:

Apache License

If you think the Android project FishApp 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 com.tschuy.fishapp;
/*from ww w  .j a  v a2  s. c o m*/
import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * A fragment representing a list of Items.
 * <p/>
 * Large screen devices (such as tablets) are supported by replacing the ListView
 * with a GridView.
 * <p/>
 * Activities containing this fragment MUST implement the {@link OnFragmentInteractionListener}
 * interface.
 */

public class VendorProductListFragment extends ListFragment implements AbsListView.OnItemClickListener {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    VendorActivity my_view;

    private OnFragmentInteractionListener mListener;

    /**
     * The fragment's ListView/GridView.
     */
    public ListView mListView;

    /**
     * The Adapter which will be used to populate the ListView/GridView with
     * Views.
     */
    ArrayAdapter<VendorProduct> mAdapter;

    // TODO: Rename and change types of parameters
    public static ListFragment newInstance(String param1, String param2) {
        ListFragment fragment = new ListFragment();
        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 VendorProductListFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        my_view = (VendorActivity) getActivity();
        mAdapter = new ArrayAdapter<VendorProduct>(my_view, R.layout.text, new ArrayList<VendorProduct>());
        setListAdapter(mAdapter);
        mAdapter.getContext();
    }

    public void setHeight() {
        mListView = getListView();
        Utils.setListViewHeightBasedOnChildren(mListView);
        return;
    }

    public void onListItemClick(ListView l, View v, int position, long id) {
        VendorProduct vendor_product = (VendorProduct) l.getItemAtPosition(position);
        my_view.vpClicked(vendor_product);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {}



    public void addItem(VendorProduct newVendorProduct) {
        mAdapter.add(newVendorProduct);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.vendor_product_list, container, false);

        // Set the adapter
        mListView = (ListView) view.findViewById(android.R.id.list);
        ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

        // Set OnItemClickListener so we can be notified on item clicks
        mListView.setOnItemClickListener(this);
        return view;
    }

    @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 onActivityCreated (Bundle savedInstanceState) {
        setHeight();
        super.onActivityCreated(savedInstanceState);
    }

    /**
     * The default content for this Fragment has a TextView that is shown when
     * the list is empty. If you would like to change the text, call this method
     * to supply the text it should use.
     */
    public void setEmptyText(CharSequence emptyText) {
        View emptyView = mListView.getEmptyView();

        if (emptyView instanceof TextView) {
            ((TextView) emptyView).setText(emptyText);
        }
    }

    /**
     * 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 onFragmentInteractionVP(VendorProduct vp);
    }

}




Java Source Code List

com.tschuy.fishapp.ApplicationTest.java
com.tschuy.fishapp.MainActivity.java
com.tschuy.fishapp.NavigationDrawerFragment.java
com.tschuy.fishapp.ProductActivity.java
com.tschuy.fishapp.Product.java
com.tschuy.fishapp.Utils.java
com.tschuy.fishapp.VendorActivity.java
com.tschuy.fishapp.VendorListFragment.java
com.tschuy.fishapp.VendorProductListFragment.java
com.tschuy.fishapp.Vendor.java