Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Android Kotlin中的导航栏标题为空_Android_Kotlin - Fatal编程技术网

Android Kotlin中的导航栏标题为空

Android Kotlin中的导航栏标题为空,android,kotlin,Android,Kotlin,我试图在TestProjectList类活动中显示导航栏标题,但该值为空,因此无法看到导航栏磁贴。我不知道为什么它显示空值。谢谢你的帮助 Model Class: class TestProject(val name: String,val location: String) Main Class: private class ItemDetailAdapter(val TestProjectList:Array<TestProject>): RecyclerV

我试图在TestProjectList类活动中显示导航栏标题,但该值为空,因此无法看到导航栏磁贴。我不知道为什么它显示空值。谢谢你的帮助

Model Class:
class TestProject(val name: String,val location: String)

Main Class:     
     private class ItemDetailAdapter(val TestProjectList:Array<TestProject>): RecyclerView.Adapter<ItemDetailViewHolder>()
    {

        override fun onBindViewHolder(p0: ItemDetailViewHolder, p1: Int) {
            val TestProject=TestProjectList.get(p1)
            p0?.customView?.TestProjectName?.text=TestProject.name
            val TestProjectPicture=p0?.customView?.itemPicture
            Picasso.get().load(TestProject.location).into(TestProjectPicture)

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

        }
        override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ItemDetailViewHolder {
            val layoutInflater=LayoutInflater.from(p0?.context)
            val customView=layoutInflater.inflate(R.layout.items_details,p0,false)
                        return ItemDetailViewHolder(customView)
        }
    }
    class ItemDetailViewHolder(val customView:View,var Title: TestProject?=null):RecyclerView.ViewHolder(customView)
    {
        companion object {
        val ITEM_TITLE_KEY="TestProject"
        }
        init {
            customView.setOnClickListener {
                val intent= Intent(customView.context,TestProjectMenuList::class.java)
                intent.putExtra(ITEM_TITLE_KEY,Title?.name)
                print("Printting Title :$Title?.name")
                println("Hello Test $ITEM_TITLE_KEY")
                customView.context.startActivity(intent)
                println("Test")
            }
        }

    TestProjectList Class:
        val navBarTitle=intent.getStringExtra(MainClass.ItemDetailViewHolder.ITEM_TITLE_KEY)
        supportActionBar?.title=navBarTitle
模型类:
类TestProject(val名称:String,val位置:String)
主要类别:
私有类ItemDetailAdapter(val TestProjectList:Array):RecyclerView.Adapter()
{
覆盖onBindViewHolder(p0:ItemDetailViewHolder,p1:Int){
val TestProject=TestProjectList.get(p1)
p0?.customView?.TestProjectName?.text=TestProject.name
val TestProjectPicture=p0?.customView?.itemPicture
Picasso.get().load(TestProject.location).into(TestProjectPicture)
}
重写getItemCount():Int{
返回TestProjectList.size
}
重写CreateViewHolder(p0:ViewGroup,p1:Int):ItemDetailViewHolder{
val layoutInflater=layoutInflater.from(p0?.context)
val customView=layoutInflater.flate(右布局项目\详细信息,p0,false)
return ItemDetailViewHolder(customView)
}
}
类ItemDetailViewHolder(val customView:View,var Title:TestProject?=null):RecyclerView.ViewHolder(customView)
{
伴星{
val ITEM_TITLE_KEY=“TestProject”
}
初始化{
customView.setOnClickListener{
val intent=intent(customView.context,TestProjectMenuList::class.java)
意向.额外(项目名称、标题、名称)
打印(“打印标题:$Title?.name”)
println(“你好测试$ITEM\u TITLE\u KEY”)
customView.context.startActivity(意图)
println(“测试”)
}
}
TestProjectList类:
val navBarTitle=intent.getStringExtra(MainClass.ItemDetailViewHolder.ITEM\u TITLE\u KEY)
supportActionBar?.title=navBarTitle
型号类别:
类TestProject(val名称:String,val位置:String)
主要类别:
私有类ItemDetailAdapter(val TestProjectList:Array):RecyclerView.Adapter()
{
覆盖onBindViewHolder(p0:ItemDetailViewHolder,p1:Int){
val TestProject=TestProjectList.get(p1)
p0?.customView?.TestProjectName?.text=TestProject.name
val TestProjectPicture=p0?.customView?.itemPicture
Picasso.get().load(TestProject.location).into(TestProjectPicture)
//下面的代码解决了标题问题
p0?.Title=测试项目
}
重写getItemCount():Int{
返回TestProjectList.size
}
重写CreateViewHolder(p0:ViewGroup,p1:Int):ItemDetailViewHolder{
val layoutInflater=layoutInflater.from(p0?.context)
val customView=layoutInflater.flate(右布局项目\详细信息,p0,false)
return ItemDetailViewHolder(customView)
}
}
类ItemDetailViewHolder(val customView:View,var Title:TestProject?=null):RecyclerView.ViewHolder(customView)
{
伴星{
val ITEM_TITLE_KEY=“TestProject”
}
初始化{
customView.setOnClickListener{
val intent=intent(customView.context,TestProjectMenuList::class.java)
意向.额外(项目名称、标题、名称)
打印(“打印标题:$Title?.name”)
println(“你好测试$ITEM\u TITLE\u KEY”)
customView.context.startActivity(意图)
println(“测试”)
}
}
TestProjectList类:
val navBarTitle=intent.getStringExtra(MainClass.ItemDetailViewHolder.ITEM\u TITLE\u KEY)
supportActionBar?.title=navBarTitle

当您在适配器中创建viewholder
返回ItemDetailViewHolder(customView)
时,您没有为参数
Title
传递任何值。您也没有在后面设置它,但是您正在用
intent.putExtra(ITEM\u Title\u KEY,Title?.name)填充intent
。在这种情况下,您将始终从intent中检索的值将为
null

调试navBarTitle值?@sasikumar感谢您的响应,但该值为NullPutExtral传递值是否正确?我不确定,因为根据代码,我传递的是正确的值debug Title?。请命名该值
Model Class:
class TestProject(val name: String,val location: String)

Main Class:     
     private class ItemDetailAdapter(val TestProjectList:Array<TestProject>): RecyclerView.Adapter<ItemDetailViewHolder>()
    {

        override fun onBindViewHolder(p0: ItemDetailViewHolder, p1: Int) {
            val TestProject=TestProjectList.get(p1)
            p0?.customView?.TestProjectName?.text=TestProject.name
            val TestProjectPicture=p0?.customView?.itemPicture
            Picasso.get().load(TestProject.location).into(TestProjectPicture)
//Below code solved the Title Problem
                p0?.Title=TestProject
        }
        override fun getItemCount(): Int {
            return TestProjectList.size

        }
        override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ItemDetailViewHolder {
            val layoutInflater=LayoutInflater.from(p0?.context)
            val customView=layoutInflater.inflate(R.layout.items_details,p0,false)
                        return ItemDetailViewHolder(customView)
        }
    }
    class ItemDetailViewHolder(val customView:View,var Title: TestProject?=null):RecyclerView.ViewHolder(customView)
    {
        companion object {
        val ITEM_TITLE_KEY="TestProject"
        }
        init {
            customView.setOnClickListener {
                val intent= Intent(customView.context,TestProjectMenuList::class.java)
                intent.putExtra(ITEM_TITLE_KEY,Title?.name)
                print("Printting Title :$Title?.name")
                println("Hello Test $ITEM_TITLE_KEY")
                customView.context.startActivity(intent)
                println("Test")
            }
        }

    TestProjectList Class:
        val navBarTitle=intent.getStringExtra(MainClass.ItemDetailViewHolder.ITEM_TITLE_KEY)
        supportActionBar?.title=navBarTitle