Tag: 安卓

Android注释与Kotlin和生成工具2.3.0

要在2.3.0之前使用Android Annotations,人们可以这样做: dependencies { apt “org.androidannotations:androidannotations:$AAVersion” compile “org.androidannotations:androidannotations-api:$AAVersion” } 要使用Kotlin,您将使用kapt而不是apt ( 链接 )。 从2.3.0开始,一个人需要使用annotationProcessor来代替apt: annotationProcessor “org.androidannotations:androidannotations:$AAVersion” compile “org.androidannotations:androidannotations-api:$AAVersion” 有没有人知道需要更改以注释处理程序使用Kotlin? 我目前有一个非常简单的主要活动,我使用@EActivity来设置布局。 我在manifest, .MainActivity_声明了生成的文件。 在Java中,这工作正常。 在Kotlin: @EActivity(R.layout.activity_main) open class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } 我得到一个运行时错误: 过程:[…],PID:10018 java.lang.RuntimeException:无法实例化活动ComponentInfo {[…]。MainActivity_}:java.lang.ClassNotFoundException:没有find类“[…]”。 MainActivity_“的路径:DexPathList [[zip文件”/data/app/[…]-1/base.apk”],nativeLibraryDirectories=[/data/app/[…]-1/lib/x86, / vendor / lib,/ system / lib]] ****更新**** 所以我清理并重建了这个项目。 看起来注解不是为MainActivity生成下划线文件。 […]

如何在不使用kotlin中的Asynctask的情况下调用Api的百分比进度?

目的 :我使用retrofit库进行api调用时使用progress dialog 。 为此,我使用下面的代码: private var progressDialog: ProgressDialog? = null @JvmStatic fun showProgress(message: String?, context: Context?, cancellable: Boolean) { if (context == null) return if (checkProgressOpen()) return progressDialog = ProgressDialog(context) (progressDialog as ProgressDialog).setProgressStyle(ProgressDialog.STYLE_SPINNER) (progressDialog as ProgressDialog).setMessage(message ?: “Please wait…”) (progressDialog as ProgressDialog).setCancelable(cancellable) try { (progressDialog as ProgressDialog).show() } catch (e: Exception) { // catch […]

从Android Studio中的播放图标开始检测测试,将它们作为JVM上的JUnit运行

当我尝试在Android Studio中通过单击文件左侧的装订线中的播放图标来运行检测测试时,它会创建错误的运行配置。 我正在使用Android Studio 3.0.1。 这似乎只发生在测试写在Kotlin。

房间持久性@Relation在Java中工作,但不在Kolin中

基于我以前的问题( Android持久性房间:“无法弄清楚如何从光标读取这个字段” ),我得到了工作,感谢反馈,我在Kolin实现了同样的例子(见下面的代码)。 我不得不做一些小的改变,如现在传递给查询的参数,这些参数必须作为“p0”,“p1”等传递。现在在Kotlin中,我得到以下有关UserWithPets类的错误: 错误:无法弄清楚如何从光标读取此字段。 e:private java.util.List宠物; @Dao interface UserDAO { @get:Query(“SELECT * FROM user”) val all: LiveData<List> @Insert fun insertUser(user: User) //single one @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertUsers(vararg users: User) @Query(“SELECT * FROM User”) fun loadUsersWithPets(): LiveData<List> } @Entity class Pet( var name: String?, var ownerId: Int,@PrimaryKey(autoGenerate = true)var id:Int) @Dao interface PetDAO { […]

有什么办法停止崩溃在kotlin的EditText中的空十进制值?

当我们把一个空的值,我需要在我的应用程序的帮助。 当我尝试计算是否有任何方法来防止崩溃,如果没有价值。 只是我需要,当我按下计算按钮,它将文本设置为“把一个值”的答案 当我尝试将字符串转换为DecimalorNulltypes只是在计算中得到错误,并防止它建立 这里是我的布局xml 这里是我的主要活动kt文件: calculate.setOnClickListener { val s = distance.text.toString().toDouble() val u = initalVelocity.text.toString().toDouble() val t = time.text.toString().toDouble() val a = (((2* s))-(2*(u*t)))/(t*t) answer.setText(“answer $am/(s)^2”) } 图片

本地函数访问具有相同名称的父variables

这更像是我在kotlin上发表的一个好奇心问题 我正在使用本地函数,它具有与其父项相同的参数名称。 看看这个例子: fun outerFunction(a: Int, b:Int) { fun localFunction(a: Int) { print(a) //local a print(b) //parent b print(???) //parent a? } } 在本地函数里面,我正在打印本地a,父b,并且有什么办法打印父a?

Android Studio 3.0会添加参数提示信息吗?

下面的示例代码由Kotlin fun detailIntent.putExtra(“Person”, SampleData.BOB)在Android Studio 3.0中显示,我发现fun detailIntent.putExtra(“Person”, SampleData.BOB)显示为detailIntent.putExtra(name: “Person”, SampleData.BOB)和I不能在编辑器中删除name 。 看来,Android Studio 3.0添加参数提示信息的名称,对不对? 以及如何设置打开或关闭它?

在Android Studio的“工具”菜单下没有出现Android菜单。 如何把它提出来?

我正在尝试使用AVD管理器制作模拟器,但是我需要转到“工具”下的Android菜单。 它不在(Firebase和Kotlin是,虽然)。 我怎样才能在这里的Android菜单?

如何在Kotlin中使用Retrofit和Observable创建异步调用?

我想使用Retrofit2库进行API调用,返回genericstypesobservable。 我得到一个错误:android.os.NetworkOnMainThreadException,同时进行调用。

升级到编译sdk版本后,findViewById出现错误

升级到编译SDK版本26后,所有findViewById显示错误: 没有足够的信息来推断有趣的参数T findViewById(id:Int):T!