Tag: 安卓

构造器在kotlin派生类中的可分解构造器

这是我之前询问的一个问题的后续。 我使用https://github.com/nekocode/android-parcelable-intellij-plugin-kotlin上的Android Parcelable插件按照bennyl的建议,我将构造函数生成的代码更改为 class ChessClock(context:Context) : TextView(context), Parcelable { lateinit var player:String constructor(context:Context, p:String, angle:Float) : this(context) { player = p rotation = angle } } 这就摆脱了我所问过的语法错误。 我现在还有一个问题,一开始我就忽视了。 该插件为writeToParcel生成了这个代码: override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeString(player) parcel.writeFloat(rotation) parcel.writeLong(mTime) parcel.writeInt(mState) } 和这个构造函数: constructor(parcel: Parcel) :this() { player = parcel.readString() rotation = parcel.readFloat() mTime = parcel.readLong() […]

Kotlin,generics和一个可能没有任何参数的函数

我试图将这个样板转化成一个非常常见的模式,Kotlin让我感到非常亲近。 我已经构建了一个类作为监听器管理器,如下所示: class GenericListenerSupport Unit> { private val listeners = mutableListOf() fun addListener(listener: ListenerFunction) { listeners.add(listener) } fun removeListener(listener: ListenerFunction) { listeners.remove(listener) } fun fireListeners(argument: EventArgumentType) { listeners.forEach { it.invoke(argument) } } } 它可以使用如下: class ExampleWithArgument { private val listenerSupport = GenericListenerSupportUnit>() fun exampleAdd() { listenerSupport.addListener({ value -> System.out.println(“My string: “+value)}) } fun exampleFire() { […]

Kotlin setTargetFragment

我有问题要调用对话框回调。 我在用: class PerfilFragment : Fragment() { val fragment = MyDialog() fragment.setTargetFragment(**this**, 1) val fm = activity.fragmentManager fragment.show(fm, “myfragment”) } 但setTargetFragment方法要求一个片段,而不是我运行的PerfilFragment : Type mismatch – Required: fragment, found PerfilFragment

如何获得日期从7天前到今天在Kotlin?

我想从7天前到Kotlin的日期。 有什么建议么? 这是我迄今为止 val date = Calendar.getInstance() val yesterday = Calendar.getInstance() yesterday.add(Calendar.DATE,-1) var todayOrYesterday:String? var todayDate = date.time while (todayDate > yesterday.time){ val formatter = SimpleDateFormat(“EEEE, d MMMM yyyy”) val format = formatter.format(todayDate) println(format) todayOrYesterday = if (DateUtils.isToday(date.timeInMillis)) { “Today” }else “Yesterday” date.add(Calendar.DATE,-7) }

Kotlinx不能解决符号“合成”

尝试Kotlin,在项目中配置Kotlin,添加了kotlin-android-extensions ,还添加了依赖… import kotlinx.android.**synthetic**.main.content_main.* [

如何在不使用HTTP的情况下在KOTLIN android中请求API响应?

我是Android开发人员,我是KOTLIN的新成员。 我还没有得到任何文件。 我试过Volley图书馆: compile ‘com.panxw.volley:library:1.0.1’

如何使用kotlin以编程方式在android中创建活动全屏。

如何使用kotlin以编程方式在android中创建活动全屏。 谢谢!

Android Kotlin界面

我有两个模块管理器和屏​​幕。 管理器使用屏幕现在我创建了一个名为EventListener屏幕内的新界面当我在Manager模块内部实现EventListener我得到错误 错误:以下类的超types无法解析。 请确保您在类路径中具有所需的依赖关系:class whitelable.rapyd.com.rapydwlmanager.RapydManager,unresolved supertypes:whitelable.rapyd.com.rapydwlscreens.EventsListener 这是我的代码: RapydManager constructor(mContext : Context) : BaseRapydManager(mContext) , EventsListener { override fun onEventDispatched(str: String) { TODO(“not implemented”) //To change body of created functions use File | Settings | File Templates. } // override fun onEventDispatched(str: String) { // screenManager.launchActivity(ActivityB::class.java,null) // } } 我尝试干净,干净的缓存,重建,删除生成目录…它does not’t工作我能做什么? 这是我的阶梯: android { compileSdkVersion 26 […]

编译kotlin类扩展java类时出错

我有下一个Java类: public interface Callbacks { void onImagePickerError(Exception e, Library.ImageSource source, int type); void onImagePicked(File imageFile, Library.ImageSource source, int type); void onCanceled(Library.ImageSource source, int type); } 和下一个抽象类扩展接口: public abstract class DefaultCallback implements Callbacks { @Override public void onImagePickerError(Exception e, Library.ImageSource source, int type) { } @Override public void onCanceled(Library.ImageSource source, int type) { } } 在我的情况下需要在一个地方扩展这个接口,并使用它来自外部库回调。 […]

Android-Kotlin中如何从单元获取字符串

我使用Okhttp3 GET方法到Web服务 val client= OkHttpClient() fun login_Chk(id:String,pw:String) { val req=Request.Builder() .url(“https://www.hxxxxxx.com/WebService.asmx/Login_Check?ID=${id}&PW=${pw}”) .build() client.newCall(req).enqueue(object : Callback{ override fun onFailure(call: Call, e: IOException) {} override fun onResponse(call: Call, res: Response) { println(res.body()?.string().toString()) return } }) } 我想检查web服务返回其“成功”或“失败” 下面我的Logcat android/bKfiHsgc_o.png 在C#中我们可以使用像 if(webservice(ID,PW) ==”Success”) { …… } 但在科特林,我不知道该怎么做。 谢谢