PDA

Ver la Versión Completa : [ SOLUCIONADO ] Paso de parametros a interface


Merche300
06/07/19, 10:55:15
Como puedo pasar la variable num_jor, dentro del if, a la interface en el metodo getData.getDataApi000.getClient.getActJuvenil? Lo que quiero es pasar el index de la mutableList a la interface, ya que es parte de la url que hay que acceder.


class FragActual : Fragment() {

var dataList = ArrayList<ActModel>()
lateinit var recyclerView: RecyclerView

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.actual_list, container, false)
return view
}


SuppressLint("SimpleDateFormat")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val progressBar: ProgressBar = this.progressBar1

recyclerView = view.findViewById(R.id.recycler_view)
recyclerView.adapter= ActAdapter(dataList,activity!!)
recyclerView.layoutManager = LinearLayoutManager(context!!,LinearLayoutManager. VERTICAL,false)

Thread(Runnable {
activity!!.runOnUiThread {
progressBar.visibility = View.VISIBLE
}

try {
var i = 0
while(i < Int.MAX_VALUE){
i++
}
} catch (e: InterruptedException) {
e.printStackTrace()
}

activity!!.runOnUiThread {
progressBar.visibility = View.GONE
}
}).start()

val mutableList: MutableList<String> = mutableListOf(
"1/6/2019", "8/6/2019", "16/6/2019", "24/6/2019", "1/7/2019", "8/7/2019", "15/7/2019", "30/7/2019", "15/8/2019", "30/8/2019",
"1/9/2019", "8/9/2019", "16/9/2019", "24/9/2019", "1/10/2019", "8/10/2019", "15/10/2019", "30/10/2019", "15/11/2019", "30/11/2019",
"1/12/2019", "8/12/2019", "16/12/2019", "24/12/2019", "1/7/2020", "8/7/2020", "15/7/2020", "30/7/2020", "15/8/2019", "30/6/2019")

for ((indice, item) in mutableList.withIndex()) {
val indice = indice+1

val date = Calendar.getInstance()

val dateformatter = SimpleDateFormat("d/M/yyyy")
val fechaInicial = (dateformatter.format(date.time))

val date2 = Calendar.getInstance()
date2.add(Calendar.DATE, 7)

val dateformatter1 = SimpleDateFormat("d/M/yyyy")
val fechaFinal = (dateformatter1.format(date2.time))

if (item == fechaInicial){

val num_jor = indice
}
}
getData()
}

private fun getData() {
val call: Call<List<ActModel>> = Api000.getClient.getActJuvenil(num_jor)
call.enqueue(object : Callback<List<ActModel>> {

override fun onResponse(call: Call<List<ActModel>>?, response: Response<List<ActModel>>?) {
dataList.addAll(response!!.body()!!)
recyclerView.adapter!!.notifyDataSetChanged()
}

override fun onFailure(call: Call<List<ActModel>>?, t: Throwable?) {
}
})
}
}