Tag: 安卓

预期的类型ID资源

我正在使用ANKO建立简单的项目。 当我尝试为EditText设置id时,出现以下错误。 确保传递给API的资源ID是正确的类型; 例如,调用Resources.getColor(R.string.name)是错误的。 import android.support.v7.app.AppCompatActivity import android.os.Bundle import org.jetbrains.anko.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) relativeLayout { editText{ id = 1 } } } }

应用程序图标不显示在Android版本大于4.4.2的设备上

使用Android Studio 3.0 Canary进行Android项目3.除了Android版本大于4.4.2的设备上不显示应用程序图标外,一切正常。 以下是清单代码。 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tanamo.dicto"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name="com.tanamo.dicto.ui.Flash" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.tanamo.dicto.ui.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme"> <intent-filter> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" /> […]

变量被声明为var,但编译器正在说val

编译器给我错误 错误:(97,17)Val不能被重新分配 但该变量被声明为var 。 编辑:你可以在我的代码中看到评论。 当我分配rcv = recyclerView和 chkStrictSearch =复选框我在这里得到红色下划线与上面的错误消息工具提示 以下是我的代码: private var rcv: RecyclerView? = null private var chkStrictSearch: android.widget.CheckBox? = null private fun getMainView(): View{ return with(context){ frameLayout{ lparams(width = matchParent, height = matchParent) //Error is below – val cannot be reassign rcv = recyclerView{ lparams(width = matchParent, height = matchParent) setPadding(0, resources.getDimension(R.dimen.toolbar_height).toInt(), […]

安科 – 替代隐藏一个观点,并显示另一个

我应该只是初始化和保持两者,并根据状态设置visibility或GONE visibility ? 有更好的方法吗? 内存问题呢? 我想交替使用RecyclerView和WebView。 我想避免碎片 – 我已经尝试过了,Activity,UI和Fragments之间的责任分离是一个地狱。 如果有问题,我将我的UI(从AnkoComponent继承而来)保存在一个单独的类中。

从Observable获取结果 – Kotin Android

我有一个方法返回Observable,如下所示: fun currentLocation(): Observable<LatLngFix> { if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) != ConnectionResult.SUCCESS || !context.isLocationPermissionGranted()) { return getDefaultLocation() } // lastKnownLocation returns location or complete without result // in the latter case, return default unknown location return Observable .concat(locationProvider.lastKnownLocation.map { val latLng = LatLngFix(it.latitude, it.longitude) return@map latLng }, getDefaultLocation()) .onErrorResumeNext { getDefaultLocation() } .first() } 然后当我调用这个函数,我想获得latlng变量。 所以我需要订阅的Observable oviously,但不知道为什么,下面给出了一个错误: localisationService.currentLocation().subscribe(latLng […]

Android Retrofit 2同步通话

我需要同步调用刷新身份验证令牌,但我得到了“ NetworkOnMainThreadException ”。 @Synchronized fun refreshToken(): String? { val refreshToken = AuthService.getRefreshToken(context) var id_token: String? = null val call = apiService.refreshToken("refresh_token", refreshToken) val response = call.execute() id_token = response.body() if (id_token != null) { AuthService.saveTokens(context, id_token) } }) return id_token } 我应该如何避免“NetworkOnMainThreadException”? D/OkHttp: –> POST https://localhost/api/auth/refresh http/1.1 (372-byte body) D/OkHttp: <– HTTP FAILED: android.os.NetworkOnMainThreadException D/AndroidRuntime: […]

点击ViewHolder中的RecyclerView项目

在我的ViewHolder中,我有一个函数: private fun setupAmountLabel(amountLabelView: CategorizedAmountView, category: Category?, amount: Double, percent: String, isParentView: Boolean) { amountLabelView.setTitle(category?.getLocalizedName() ?: "") amountLabelView.setSubTitle(percent) amountLabelView.setAmountSignType(AmountType.NEGATIVE) amountLabelView.setAmountAndCurrencyCode(amount, currencyCode) amountLabelView.setIconCategory(category) amountLabelView.setAmountColor(amount.toDataSetColor()) amountLabelView.setOnClickListener { listItemClickListener?.onListItemClick(if (isParentView) 1 else 0, category?.guid ?: "") } } 在哪里我想点击我的listItemParent。 早些时候,这个函数在适配器中,我通过创建setListClickListener方法来调用适配器。 但是现在我不知道如何点击这个项目。

为什么我的工作没有开始?

我尝试使用JobSchedulers为我的聊天应用程序(用于异步发送消息): val job = dispatcher.newJobBuilder() .setService(BackgroundJobService::class.java) .setTag(BackgroundJobService.TASKTAG_SEND_MESSAGE) .setReplaceCurrent(false) .setConstraints(Constraint.ON_ANY_NETWORK) .setExtras(bundle) .setTrigger(Trigger.executionWindow(0, 1)) .build() dispatcher.mustSchedule(job) 并在清单中添加我的服务: <service android:exported="false" android:name=".data.background.service.BackgroundJobService"> <intent-filter> <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/> </intent-filter> </service> 我写这个JobService,它不调用onCreate(),并没有调用onDestroy() class BackgroundJobService : JobService() { companion object { val TASKTAG_SEND_MESSAGE = "send_message" } @Inject lateinit var webSocket: IRxWebSocket var subscribe: Disposable? = null override fun onCreate() { super.onCreate() App.appComponent.inject(this) subscribe = […]

AdMob RewardedVideoAd一直在后台运行

所以我有一个领域: private lateinit var adMobAd: RewardedVideoAd 我在onCreate()方法中初始化它: adMobAd = MobileAds.getRewardedVideoAdInstance(this) 我在onDestroy()方法中销毁: public override fun onDestroy() { adMobAd.destroy(this) super.onDestroy() } 但是当我点击按钮来加载广告,然后快速离开活动,一个广告几秒钟后显示(我在onRewardedVideoAdLoaded()回调中显示广告)。 这是非常不好的行为,特别是当广告不可跳过时。 当它完成时,它也会调用回调函数,所以当然我得到了崩溃。 另外,我使用一些调解来奖励我的视频 implementation 'com.google.ads.mediation:adcolony:3.1.2.0' implementation 'com.google.ads.mediation:tapjoy:11.11.0.0' implementation 'com.google.ads.mediation:unity:2.1.0.0' 我怎样才能防止这种情况?

使用RxJava获得与领域和改造的独特结果

我知道Dan Lew几乎回答了从不同来源获取数据的问题 .concat(/*…*/) .take(1) 但是,如果不是从我的本地存储的数据和改造的用户列表。 在显示结果之前,我需要对数据执行特定于数据库的操作,例如只显示不同的用户。 在这种情况下,简单地在我的网络请求和本地数据上使用concat运算符将不会返回相同的结果。 有没有用RxJava写这个习惯用法?