Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 颊_Kotlin_Do While - Fatal编程技术网

Kotlin 颊

Kotlin 颊,kotlin,do-while,Kotlin,Do While,我正试图从列表中删除这个名字,但什么都没有,里面有所有内容,我只想让你告诉我matematicas和其他我要添加的主题 { "id": 419704, "page": 1, "total_results": 0, "total_pages": 0, "results": [ { "id": 1, "nom_prof": "nombre profesor", "asign

我正试图从列表中删除这个名字,但什么都没有,里面有所有内容,我只想让你告诉我matematicas和其他我要添加的主题

{
    "id": 419704,
    "page": 1,
    "total_results": 0,
    "total_pages": 0,
    "results": [
        {
            "id": 1,
            "nom_prof": "nombre profesor",
            "asignaturas": [
                {
                    "matematicas": {
                        "lunes": {
                            "hora1": "x",
                            "hora2": "x",continue.... 
这就是我能想到的

  clasigicacion.asignaturas.forEach {
   itemView.tv_asignaturas.text = it.toString()              
}

这是一份名单

这是使事情看起来更好的适配器

class TeachAdapter (val profesores: ArrayList<Results.Profesores>): androidx.recyclerview.widget.RecyclerView.Adapter<TeachAdapter.ClasiViewHolder>() {

private var context: Context? = null

override fun onBindViewHolder(holder: ClasiViewHolder, position: Int) {
    val itemClasi = profesores[position]
    holder.bindClasificacion(itemClasi)

    holder.itemView.setOnClickListener{

        //Toast.makeText(context, "settings", Toast.LENGTH_SHORT).show()

        val bundle = Bundle()
        bundle.putString("nom_prof", itemClasi?.nom_prof)
        bundle.putString("img_profe", itemClasi?.img_profe)
        bundle.putString("img_fondo", itemClasi?.img_fondo)
        bundle.putString("asignatura", itemClasi.asignaturas[0].nom_asignatura)
        bundle.putString("lunes_1", itemClasi.asignaturas[0].lunes?.hora1)
        bundle.putString("lunes_2", itemClasi.asignaturas[0].lunes?.hora2)
        bundle.putString("lunes_3", itemClasi.asignaturas[0].lunes?.hora3)
        bundle.putString("lunes_4", itemClasi.asignaturas[0].lunes?.hora4)
        bundle.putString("lunes_5", itemClasi.asignaturas[0].lunes?.hora5)
        bundle.putString("lunes_6", itemClasi.asignaturas[0].lunes?.hora6)
        context!!.startActivity(Intent(context, DetProfesor::class.java).putExtras(bundle))
    }
}

override fun getItemCount(): Int {
    return profesores.size
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClasiViewHolder {
   val layoutInflate = LayoutInflater.from(parent.context)
           .inflate(R.layout.teach_row, parent, false)

    context = parent.context

    return ClasiViewHolder(layoutInflate)
}

class ClasiViewHolder(itemView: View): androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView){
    @SuppressLint("SetTextI18n", "LogNotTimber")
    fun bindClasificacion(profesores: Results.Profesores){

        Picasso.get()
            .load(Constants.URL_IMAGES + profesores.img_profe)
            .resize(50, 50)
            .centerCrop()
            .into(itemView.civ_imageProf)

        //Log.d("Tag xxx: ", clasigicacion.nom_prof)

        itemView.tv_namProf.text = profesores.nom_prof

        itemView.tv_asignaturas.text = profesores.asignaturas[0].nom_asignatura

        for ((k, v) in profesores.asignaturas) {

                println("key: $k  values - $v")
        }
    }
}
class TeachAdapter(val profesores:ArrayList):androidx.recyclerview.widget.recyclerview.Adapter(){
私有变量上下文:上下文?=null
覆盖BindViewHolder(holder:ClasiViewHolder,位置:Int){
val itemClasi=教授[职位]
持有人:bindClasificacion(项目分类)
holder.itemView.setOnClickListener{
//Toast.makeText(上下文,“设置”,Toast.LENGTH\u SHORT.show())
val bundle=bundle()
bundle.putString(“nom_prof”,itemClasi?.nom_prof)
bundle.putString(“img_profe”,itemClasi?.img_profe)
bundle.putString(“img_fondo”,itemClasi?.img_fondo)
bundle.putString(“asignatura”,itemClasi.asignaturas[0]。nom_asignatura)
bundle.putString(“lunes_1”,itemClasi.asignaturas[0]。lunes?.hora1)
bundle.putString(“lunes_2”,itemClasi.asignaturas[0]。lunes?.hora2)
bundle.putString(“lunes_3”,itemClasi.asignaturas[0]。lunes?.hora3)
bundle.putString(“lunes_4”,itemClasi.asignaturas[0]。lunes?.hora4)
bundle.putString(“lunes_5”,itemClasi.asignaturas[0]。lunes?.hora5)
bundle.putString(“lunes_6”,itemClasi.asignaturas[0]。lunes?.hora6)
context!!.startActivity(Intent(context,DetProfesor::class.java).putExtras(bundle))
}
}
重写getItemCount():Int{
返回参数
}
override fun onCreateViewHolder(父级:ViewGroup,viewType:Int):ClasiViewHolder{
val layoutInflate=LayoutInflater.from(parent.context)
.充气(右布局,示教行,父级,假)
context=parent.context
回料架(平放)
}
类ClasiViewHolder(itemView:View):androidx.recyclerview.widget.recyclerview.ViewHolder(itemView){
@SuppressLint(“SetTextI18n”、“LogNotTimber”)
fun bindClasificacion(教授:结果。教授){
毕加索
.load(Constants.URL\u IMAGES+profesores.img\u profe)
.调整大小(50,50)
.centerCrop()
.into(itemView.civ_imageProf)
//Log.d(“标签xxx:,clasigicacion.nom_prof”)
itemView.tv_namProf.text=profesores.nom_prof
itemView.tv\u asignaturas.text=profesores.asignaturas[0]。nom\u asignatura
对于((k,v)在教授中,无符号){
println(“键:$k值-$v”)
}
}
}
}

这里的片段是解析器

class FragProfesores : androidx.fragment.app.Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?): View? {

        val view = inflater.inflate(R.layout.teach_list, container, false)
        return view
    }

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

        recyclerView.layoutManager = GridLayoutManager(context, 1)
        recyclerView.adapter = null

        val progressBar: ProgressBar = this.progressBar

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

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

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

        val apiClasi = Api000.getClient.getClasificacion()

        apiClasi.enqueue(object : Callback<Results> {
            override fun onFailure(call: Call<Results>, t: Throwable?) {
               // Log.e("TAG Fallo: ", t.toString())
            }

            override fun onResponse(call: Call<Results>, response: Response<Results>) {
                for(res in response.body()!!.results){
                    //Log.d("TAG Respuesta: ", res.asignaturas!!.asig_1)
                }

                recyclerView.adapter = TeachAdapter(response.body()!!.results)
            }
        })
    }
}
类FragProfesores:androidx.fragment.app.fragment(){
覆盖创建视图(
充气器:布局充气器,容器:视图组?,
savedInstanceState:捆绑?:查看{
val视图=充气机。充气(R.layout.teach_列表,容器,错误)
返回视图
}
覆盖已创建的视图(视图:视图,保存状态:捆绑?){
super.onViewCreated(视图,savedInstanceState)
RecycleView.layoutManager=GridLayoutManager(上下文,1)
recyclerView.adapter=null
val progressBar:progressBar=this.progressBar
线程(可运行{
活动!!.runOnUiThread(java.lang.Runnable{
progressBar.visibility=View.VISIBLE
})
试一试{
变量i=0

而(iMatematicas是json的键,而不是值。您可以使用它将值映射到asignaturas.Matematicas。您可能需要重新考虑您的数据模型,以防您想将主题名称作为值。 像这样的方法应该会奏效:

{
  "asignaturas": [
    {
      "nombre": "matematicas",
      "lunes": {
        "hora1": "x",
        "hora2": "x",
        continue....
      }
    },
    {
      "nombre": "other",
      "lunes": {
        "hora1": "x",
        "hora2": "x",
        continue....
      }
    }
  ]
}
您的数据类将是:

data class Results(val results: ArrayList<Profesores>) {

    data class Profesores(
        val id: String,
        val nom_prof: String,
        val asignaturas: ArrayList<Asignaturas>,
        val img_profe: String,
        val img_fondo: String
    ) {

        data class Asignaturas(val nombre: String, val lunes: Dia?, val martes: Dia?) {
            data class Dia(
                val hora1: String,
                val hora2: String,
                val hora3: String,
                val hora4: String,
                val hora5: String,
                val hora6: String
            )
        }
    }
}
数据类结果(val结果:ArrayList){
数据类教授(
valid:String,
val nom_教授:字符串,
val asignaturas:ArrayList,
val img_教授:字符串,
val img_fondo:字符串
) {
数据类Asignaturas(val nombre:String,val lunes:Dia?,val martes:Dia?){
数据类直径(
val hora1:字符串,
val hora2:字符串,
val hora3:字符串,
val hora4:字符串,
val hora5:字符串,
val hora6:字符串
)
}
}
}

需要澄清。您想删除的名称是什么?您使用的是JSON还是实际列表?
itemView
与此处的任何内容有什么关系?“Bucles”是的,是aJson-我只想让他给我看matematicas-只有matematicas-我怎么做?循环?位置1用适配器编辑你能包括结果吗?教授?位置1用片段和模型编辑吗
data class Results(val results: ArrayList<Profesores>) {

    data class Profesores(
        val id: String,
        val nom_prof: String,
        val asignaturas: ArrayList<Asignaturas>,
        val img_profe: String,
        val img_fondo: String
    ) {

        data class Asignaturas(val nombre: String, val lunes: Dia?, val martes: Dia?) {
            data class Dia(
                val hora1: String,
                val hora2: String,
                val hora3: String,
                val hora4: String,
                val hora5: String,
                val hora6: String
            )
        }
    }
}