-
-
Save funrep/1ab655a69058f993d2237f8dfe64bf61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.animalcontrol | |
import android.app.Fragment | |
import android.content.Context | |
import android.net.Uri | |
import android.os.Bundle | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.ListView | |
import com.example.animalcontrol.Adapters.DeliveriesAdapter | |
import com.example.animalcontrol.Models.Delivery | |
import java.util.ArrayList | |
/** | |
* A simple [Fragment] subclass. | |
* Activities that contain this fragment must implement the | |
* [DeliveryListFragment.OnFragmentInteractionListener] interface | |
* to handle interaction events. | |
* Use the [DeliveryListFragment.newInstance] factory method to | |
* create an instance of this fragment. | |
*/ | |
class DeliveryListFragment : Fragment() { | |
private var deliveries: ArrayList<Delivery>? = null | |
// TODO: Rename and change types of parameters | |
private var mParam1: String? = null | |
private var mParam2: String? = null | |
private var mListener: OnFragmentInteractionListener? = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
if (savedInstanceState == null) { | |
super.onCreate(Bundle()) | |
} else { | |
super.onCreate(savedInstanceState) | |
} | |
if (arguments != null) { | |
mParam1 = arguments?.getString(ARG_PARAM1) | |
mParam2 = arguments?.getString(ARG_PARAM2) | |
} | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle): View? { | |
// Inflate the layout for this fragment | |
val view = inflater.inflate(R.layout.fragment_delivery_list, container, false) | |
listView = view.findViewById(R.id.dlfListView) as ListView | |
deliveries = ArrayList<Delivery>() | |
deliveries!!.add(Delivery("Test1")) | |
deliveries!!.add(Delivery("Test2")) | |
val deliveriesAdapter = DeliveriesAdapter(this.context, R.layout.fragment_delivery_list, deliveries as ArrayList<Delivery>, mListener!!) | |
listView!!.adapter = deliveriesAdapter | |
return view | |
} | |
// TODO: Rename method, update argument and hook method into UI event | |
fun onButtonPressed(uri: Uri) { | |
if (mListener != null) { | |
} | |
} | |
override fun onAttach(context: Context) { | |
super.onAttach(context) | |
if (context is OnFragmentInteractionListener) { | |
mListener = context | |
} else { | |
throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener") | |
} | |
} | |
override fun onDetach() { | |
super.onDetach() | |
mListener = null | |
} | |
/** | |
* 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. | |
* | |
* | |
* See the Android Training lesson [Communicating with Other Fragments](http://developer.android.com/training/basics/fragments/communicating.html) for more information. | |
*/ | |
interface OnFragmentInteractionListener { | |
// TODO: Update argument type and name | |
fun onFragmentInteraction(delivery: Delivery) | |
} | |
companion object { | |
// TODO: Rename parameter arguments, choose names that match | |
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | |
private val ARG_PARAM1 = "param1" | |
private val ARG_PARAM2 = "param2" | |
private var listView: ListView? = null | |
/** | |
* Use this factory method to create a new instance of | |
* this fragment using the provided parameters. | |
* @param param1 Parameter 1. | |
* * | |
* @param param2 Parameter 2. | |
* * | |
* @return A new instance of fragment DeliveryListFragment. | |
*/ | |
// TODO: Rename and change types and number of parameters | |
fun newInstance(param1: String, param2: String): DeliveryListFragment { | |
val fragment = DeliveryListFragment() | |
val args = Bundle() | |
args.putString(ARG_PARAM1, param1) | |
args.putString(ARG_PARAM2, param2) | |
fragment.arguments = args | |
return fragment | |
} | |
} | |
}/ |
Author
funrep
commented
Jun 4, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment