Como puedo pasar la variable jornada al pulsar un boton a la clase apiInterface?
El fragment FragJornadas, de donde quiero pasar la variable a @Get
class FragJornadas : Fragment() {
var jornada = "1"
var dataList = ArrayList<TodasModel>()
lateinit var recyclerView: RecyclerView
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.jornadas_list, container, false)
val miTexto: TextView = view.findViewById(R.id.tv_Jornadas)
miTexto.text = (getString(R.string.num_jornada))
val numJor = intArrayOf(R.id.tv_01, R.id.tv_02, R.id.tv_03, R.id.tv_04, R.id.tv_05,
R.id.tv_06, R.id.tv_07, R.id.tv_08, R.id.tv_09, R.id.tv_10, R.id.tv_11, R.id.tv_12,
R.id.tv_13, R.id.tv_14, R.id.tv_15, R.id.tv_16, R.id.tv_17, R.id.tv_18, R.id.tv_19,
R.id.tv_20, R.id.tv_21, R.id.tv_22, R.id.tv_23, R.id.tv_24, R.id.tv_25, R.id.tv_26,
R.id.tv_27, R.id.tv_28, R.id.tv_29, R.id.tv_30)
val button = arrayOfNulls<Button>(numJor.size)
for(i in numJor.indices){
button[i] = view.findViewById(numJor[i]) as Button
val buttonValue = i+1
val buttonText = Integer.toString(buttonValue)
button[i]!!.setOnClickListener {
miTexto.text = getString(R.string.num_jornada) + " " + buttonText
jornada = buttonText
getData(jornada)
}
}
return view
}
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= TodasAdapter(dataList,activity!!)
recyclerView.layoutManager=LinearLayoutManager(activity!!,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()
getData(jornada)
}
private fun getData(jornada: String) {
val call: Call<List<TodasModel>> = ApiFederacion.getClient.getTodasJuvenil(jornada)
call.enqueue(object : Callback<List<TodasModel>> {
override fun onResponse(call: Call<List<TodasModel>>?, response: Response<List<TodasModel>>?) {
dataList.addAll(response!!.body()!!)
recyclerView.adapter!!.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<TodasModel>>?, t: Throwable?) {
//progerssProgressDialog.dismiss()
}
})
}
}
Y la clase ApiInterface para recibirlo Siendo quela url que quiero conseguir es: "server.php?action=getResultados&cmp=328&jor=1&tmp=2018/2019"
@GET("server.php?action=getResultados&cmp=328{jor}tmp=2018/2019")
fun getTodasJuvenil(
@Path("jor") jornada: String
): Call<List<TodasModel>>
El error:
java.lang.IllegalArgumentException: URL query string "action=getResultados&cmp=328{jor}&tmp=2018/2019" must not have replace block. For dynamic query parameters
at com.myapplication.Jornadas.FragJornadas.getData(FragJornadas.kt:91)
at com.myapplication.Jornadas.FragJornadas.onViewCreated(FragJornadas.kt:87)