Tag: android

错误:执行任务’:app:compileDebugKotlin’失败。 >编译错误。 查看日志了解更多详情

Error:Execution failed for task ‘:app:compileDebugKotlin’. > Compilation error. See log for more details 建立:gradle这个(模块:APP) buildscript { repositories { maven { url ‘https://jitpack.io’ url ‘https://maven.fabric.io/public’ } } dependencies { classpath ‘io.fabric.tools:gradle:1.+’ } } apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ apply plugin: ‘io.fabric’ apply plugin: ‘kotlin-android-extensions’ repositories { maven { url ‘https://maven.fabric.io/public’ } mavenCentral() } android { […]

初始化有getter和setter的字段?

我在Kotlin创建了一个有示例字段的类 class SomeClass { var smth: String = “Initial value” get() = “Here it is” set(value) { field = “it is $value” } } 当我创建一个类的对象并调用smth字段时,它将会调用get()属性。 val myValue = SomeClass().smth// myValue = “Here it is” 所以,问题是:为什么我们必须初始化一个有getter的字段? var smth: String // Why this gives error? get() = “Here it is” set(value) { field = “it is $value” […]

如何使用kotlin单击listView项目中的imageButton后才能获取DB ID

我有一个customAdapter类和一个listView。 我做了3个textview和一个imageButton的single_row布局。 现在我的问题是我怎么能得到DB ID字段,只能从单击imageButton并忽略整个行上的点击? 我知道我可以得到的ID: mListView.onItemClickListener = AdapterView.OnItemClickListener { adapterView, view, position, id -> view.delete.setOnClickListener(){ Toast.makeText(context,””+id,Toast.LENGTH_SHORT).show() } 但是这只有当我点击整个行时才有效。 我在imageButton节点中的xml和android:focusable=”false” focusable android:focusable=”false”的根目录中尝试了android:descendantFocusability=”blocksDescendants” ,并且在整个行被识别时imageButton无法识别。 只有当我使用button.onClickListener()…点击被识别。 但这样我不知道如何得到身份证。 我的适配器类代码: class MyAdapter(activity: Activity, context: Context, cursor: Cursor) : CursorAdapter(context, cursor, true) { var inflater: LayoutInflater lateinit var mListView: ListView init { this.inflater = LayoutInflater.from(context) mListView = activity.listView } override fun […]

如何创建BLE设备的模拟器通过蓝牙进行通信?

我正在创建一个应用程序,我需要通过蓝牙传递数据,但是我没有BLE设备。 我想使用常见的BLE特性来通过蓝牙传递数据。 有没有可用的模拟器? 我在哪里可以测试我的申请? 我正在Kotlin开发这个应用程序,请给我一个相应的解决方案。

键盘隐藏BottomSheetDialogFragment

键盘下方有更多的字段。 这发生在我更新支持库时。 我知道这是Kotlin,但它看起来几乎与Java相同。 我该如何解决这个问题? 这是它的样子: 我的代码: class ProjectsEditBottomSheetFragment(val privateID: String, val publicID: String) : BottomSheetDialogFragment() { private val mBottomSheetBehaviorCallback = object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(bottomSheet: View, newState: Int) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { dismiss() } } override fun onSlide(bottomSheet: View, slideOffset: Float) { if (slideOffset < -0.15f) { dismiss() } } } […]

notifyDataChanged()无法更新可扩展列表视图数据

我正在开发一个可扩展的列表视图,当我创建一个奖励广告后,我想在用户观看奖励的广告之后添加一个可展开的列表视图,但应用程序崩溃的Android监视器错误。 这里是代码… class MainActivity : Activity(),RewardedVideoAdListener { override fun onRewardedVideoAdClosed() = Unit override fun onRewardedVideoAdLeftApplication() = Unit override fun onRewardedVideoAdLoaded() = Unit override fun onRewardedVideoAdOpened() = Unit override fun onRewarded(rewardedLiterature: RewardItem?) { rewardedLiterature.apply { ParentList.add(“New Articles”) ParentList.reverse() } } override fun onRewardedVideoStarted() = Unit override fun onRewardedVideoAdFailedToLoad(p0: Int) { Toast.makeText(this,”Please try again”,Toast.LENGTH_SHORT).show() } private lateinit […]

键盘在kotlin中打开时如何隐藏底部按钮?

我在我的布局中有一个EditText和一个按钮。 我的按钮是parentbottom对齐。 所以每当我尝试在edittext按钮中输入一些东西的时候它就会结束。 所以要隐藏按钮,我试了一下:` fun hideButton(editText: EditText, button: Button) { editText.viewTreeObserver.addOnGlobalLayoutListener { val r = Rect() editText.getWindowVisibleDisplayFrame(r) val screenHeight = editText.rootView.height val keypadHeight = screenHeight – r.bottom if (keypadHeight > screenHeight * 0.15) { // keyboard is open button.visibility = View.GONE } else { // keyboard is closed button.visibility = View.VISIBLE } } } 并称这个函数为: […]

将预先计算的结果从一个Kotlin活动发送到另一个文本视图

我目前正在计算我的主要活动。 计算在下面的函数中完成。 结果显示在同一屏幕上的文本框中。 ShowNumber.setText(buClickValue) Bill = buClickValue fun buCalculateEvent(view: View) { var Total = “%.2f”.format(Bill.toDouble() * .15) ShowNumber.setText(“Based on a 15% tip, you would be ” + ( Bill.toDouble() + Total.toDouble())) } 我的问题是试图让setText消息出现在另一个活动。 我知道如何通过点击一个按钮访问活动。 我也知道如何在另一个活动中生成吐司消息。 我怎样才能将信息发送到另一个活动的文本视图? 提前致谢。

Android的gradle无法find方法’org.grade.api.internal.file.DefaultSourceDirectorySet’

我试图将java类转换为Kotlin,工作正常,除了我得到了以下错误。我试图重新下载像下面suggessted所有的依赖,但无济于事。请帮助我这个错误。 错误: Error:(2, 0) Unable to find method ‘org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V’. Possible causes for this unexpected error include:Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop […]

在Android设备上使用Java / Kotlin检测音频文件(amr)中的静音

有没有我用来实现这个的库或方法? 我知道我必须一次一个地读取文件中的字节,检查它们的值是否低于或高于特定的阈值并检测到静音。 但是,我似乎无法find一个库来计算音频文件的有效值或阈值