小编Dim*_*tel的帖子

Kotlin与碎片

    var bundle : Bundle ? =null

    bundle?.putString("text",text)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        frag = Fragment.instantiate(context,Fragment2::class.java.name) as Fragment2
    }

    frag?.arguments=bundle

    fragmentManager.beginTransaction().replace(R.id.contentPanel1,frag).commit()
Run Code Online (Sandbox Code Playgroud)

我已经在fragment1上编写了这些代码并将数据传递给它

在Fragment 2上,我正在接收该包,因为null可以解决它

var bundle : Bundle ?
bundle = arguments

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    Toast.makeText(context,bundle.toString(),Toast.LENGTH_LONG).show()
}
Run Code Online (Sandbox Code Playgroud)

android android-fragments kotlin

1
推荐指数
1
解决办法
565
查看次数

Android 中带有地图的 Kotlin

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
var view: View = inflater?.inflate(R.layout.map_fragment, null)!!

var mapFragment : SupportMapFragment?=null
mapFragment= fragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)

return view
}
Run Code Online (Sandbox Code Playgroud)

日志:

FATAL EXCEPTION: main
kotlin.TypeCastException: null cannot be cast to non-null type 
com.google.android.gms.maps.SupportMapFragment
at example.com.kotlinexamplebydimple.Mapfragment.onCreateView(Mapfragment.kt:36)
Run Code Online (Sandbox Code Playgroud)

在这一行,错误显示:

mapFragment= fragmentManager.findFragmentById(R.id.map) as SupportMapFragment
Run Code Online (Sandbox Code Playgroud)

android dictionary kotlin

1
推荐指数
1
解决办法
4152
查看次数

标签 统计

android ×2

kotlin ×2

android-fragments ×1

dictionary ×1