Tag: 安卓

未解决的参考:Kotlin中的findViewById

fun Tryouts() { var CheckBox1 : CheckBox = findViewById(R.id.ForwardBox) as CheckBox CheckBox1.setChecked(false) } 我还是Kotlin的初学者,仅仅学习了kotlin的基本工作,我无法引用任何android小部件或者在Android Studio中更改它的状态,无论是TextView还是CheckBox或者RadioBox。 在所有情况下,findViewById的相同未解决的引用错误… 我不知道我在做什么错误,甚至是java转换输出相同的错误。

如何使用Kotlin从Firebase数据库检索数据?

这是我在Firebase上上传的模型: public class OnlineMatch{ private User user1; private User user2; public OnlineMatch(User firstPlayer, User secondPlayer) { this.user1 = firstPlayer; this.user2 = secondPlayer; } } 然后我以这种方式将数据发送到Firebase(kotlin): fun createMatch(match: OnlineMatch) { val matchList = database.child(“multiplayer”).push() matchList.setValue(match) } 因此,我的数据库结构如下: 如果我展开一个节点,我可以看到完美的对象:OnlineMatch(User1,User2) 现在我想查询数据库并获得一个ArrayList”。 我已经find了Firebase文档,但是我没有发现任何用处。 我能怎么做? 提前致谢。

Kotlin懒惰的默认属性

在Kotlin中,我如何定义一个具有惰性默认值的variables? 比如val就是这样的: val toolbarColor by lazy {color(R.color.colorPrimary)} 我想要做的是,有一个属性( toolbarColor )的默认值,我可以改变这个值的其他任何东西。 可能吗? 编辑:这是部分把戏。 var toolbarColor = R.color.colorPrimary get() = color(field) set(value){ field = value } 有没有可能通过写作来缓解这一点 var toolbarColor = color(R.color.colorPrimary) set(value){ field = value } 在默认值的计算方式懒惰? 目前它不会工作,因为color()需要一个只在稍后初始化的Context 。

什么是Kotlin后台?

作为Java开发人员,后台字段的概念对我来说有点陌生。 鉴于: class Sample { var counter = 0 // the initializer value is written directly to the backing field set(value) { if (value >= 0) field = value } } 这个后盾有什么好处? Kotlin的文档说: Kotlin中的类不能有字段。 但是,使用自定义访问器时有时需要有后台字段 。 为什么? 在setter中使用属性名称本身的区别是什么,例如。 class Sample { var counter = 0 set(value) { if (value >= 0) this.counter = value // […]

Android防止双击一个按钮

什么是防止双击Android中的按钮的最佳方法?

如何在kotlin中使用Android支持typedef注释?

我开发的Android应用程序,经常使用注释作为编译时间参数检查,主要是Android的支持注释 。 java代码示例: public class Test { @IntDef({Speed.SLOW,Speed.NORMAL,Speed.FAST}) public @interface Speed { public static final int SLOW = 0; public static final int NORMAL = 1; public static final int FAST = 2; } @Speed private int speed; public void setSpeed(@Speed int speed) { this.speed = speed; } } 我不想使用枚举,因为他们在Android的性能问题。 自动转换为kotlin只会产生无效的代码。 如何在kotlin中使用@IntDef批注?

Google地图视图泄漏非常多

我以前使用过MapFragment,但是我的需求很慢。 MapView几乎是即时的,完全符合我的需求。 但是他们都有一个共同点: 巨大的内存泄漏。 我已经“销毁”了MapView,就像我应该退出活动时那样,它仍然会泄漏。 MapView处于一个频繁打开和关闭的活动,并且会再次快速打开。 这可能是问题吗? 这里是我的hprof文件的一些screeenshots(我宁愿不上传hprof文件,由于可能的敏感信息): 我有多个泄漏,他们指向相同的类。 但是,我正在使用一个自定义的类,这个时候不需要,我将恢复到默认的MapView。

如何清除焦点和删除Android上的键盘?

我有一个EditText控件。 如果我点击它,softkeyboard会popup,但是当我按“enter / ok / return”,然后EditText控件它仍然有焦点和键盘。 如何关闭软键盘并从中删除焦点?

在Instant App中应用插件“kotlin-android”会导致“null不能转换为非空types的com.android.build.gradleBasePlugin”

我一直在试图将新公开发布的Android即时应用和Kotlin编程语言结合起来。 在使用以下(标准?)设置创建我的项目后,当我尝试构建应用程序时,出现错误消息“null不能转换为非空typescom.android.build.gradle.BasePlugin” 。 使用Kotlin可以很好的使用标准的“com.android.application”模块; 仅当我尝试在即时应用程序模块中使用它时,才会引发错误。 顶级build.gradle : buildscript { repositories { maven { url ‘https://maven.google.com’ } jcenter() } dependencies { classpath “com.android.tools.build:gradle:3.0.0-alpha1” classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4” } } // … 应用程序模块build.gradle ,其中Kotlin工作: apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ // This will work. android { compileSdkVersion 25 buildToolsVersion “25.0.2” defaultConfig { // … } buildTypes { release { […]

如何合并一些spannable对象?

我将一个可以跨越的对象分成三部分,做不同的操作,然后我需要合并它们。 Spannable str = editText.getText(); Spannable selectionSpannable = new SpannableStringBuilder(str, selectionStart, selectionEnd); Spannable endOfModifiedSpannable = new SpannableStringBuilder(str, selectionEnd, editText.getText().length()); Spannable beginningOfModifiedSpannable = new SpannableStringBuilder(str, 0, selectionStart); 我该怎么做? 我没有find所需的方法或构造函数来做到这一点。