小编Nou*_*hat的帖子

获取位置android Kotlin

我最近添加了获取位置功能.当我尝试显示经度和纬度时,它返回零.

这是我的LocationListener类:

inner class MylocationListener: LocationListener {
    constructor():super(){
        mylocation= Location("me")
        mylocation!!.longitude
        mylocation!!.latitude
    }

    override fun onLocationChanged(location: Location?) {
        mylocation=location
    }

    override fun onStatusChanged(p0: String?, p1: Int, p2: Bundle?) {}

    override fun onProviderEnabled(p0: String?) {}

    override fun onProviderDisabled(p0: String?) {}
}
Run Code Online (Sandbox Code Playgroud)

这是我的GetUserLocation函数:

fun GetUserLocation(){
    var mylocation= MylocationListener()
    var locationManager=getSystemService(Context.LOCATION_SERVICE) as LocationManager
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0.1f,mylocation)
}
Run Code Online (Sandbox Code Playgroud)

这是我的功能,以返回我的经度和纬度:

fun getLoction (view: View){
    prgDialog!!.show();

    GetUserLocation()

    button.setTextColor(getResources().getColor(R.color.green));
    textView.text = mylocation!!.latitude.toFloat().toString()
    Toast.makeText(this, mylocation!!.latitude.toFloat().toString(), Toast.LENGTH_LONG).show()
    Toast.makeText(this, mylocation!!.longitude.toFloat().toString(), Toast.LENGTH_LONG).show()

    prgDialog!!.hide()
} 
Run Code Online (Sandbox Code Playgroud)

android location kotlin

11
推荐指数
6
解决办法
3万
查看次数

android中的setOnLongClickListener与kotlin

我如何setOnItemClickListner在我的每个项目中使用ListView

我的xml:

<ListView
    android:id="@+id/tv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</ListView>
Run Code Online (Sandbox Code Playgroud)

这是我的适配器类

inner class mo3d1Adapter : BaseAdapter {
    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        return listOfmo3d.size
    }

    var listOfMkabala = ArrayList<MeetingDetails>()
    var context: Context? = null

    constructor(context: Context, listOfMkabaln: ArrayList<MeetingDetails>) : super() {
        this.listOfMkabala = listOfMkabaln
        this.context = context
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        val mo3d = listOfmo3d[p0]

        var inflatormo3d = context!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var myViewmo3d …
Run Code Online (Sandbox Code Playgroud)

android listview kotlin

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

我想用kotlin在android中单击Button后更改背景

我想在点击按钮后更改背景

   var bm : Button = messeg
    bm . setOnClickListener {
        bm . background = R.color.green
    }
Run Code Online (Sandbox Code Playgroud)

错误日志:

错误:(35,31)类型不匹配:推断类型是Int但可绘制!预计错误:任务':app:compileDebugKotlin'的执行失败.

编译错误.有关详细信息,请参阅日志

android background button kotlin

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×3

kotlin ×3

background ×1

button ×1

listview ×1

location ×1