Tag: 安卓

指定为非null的参数在ArrayAdaper中为null

我已经扩展了微调的ArrayAdapter: class OrderAdapter(context: Context, resource: Int, objects: List<Order>) : ArrayAdapter<Order>(context, resource, objects) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? { val view = super.getView(position, convertView, parent) view?.let { view.find<TextView>(android.R.id.text1).text = getItem(position).name } return view } override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View? { val view = super.getDropDownView(position, convertView, parent) view?.let […]

应用程序在构建回栈时崩溃

我在我的IntentService一个后退堆栈。 我收到来自Kitkat设备的崩溃报告。 我的代码很简单,我不知道可能是什么原因。 我有一个堆栈跟踪,但它没有得到我的任何地方。 任何人经历过这样的事情? override fun onHandleIntent(intent: Intent?) { if (intent != null) { val articleIntent = intentFor<ArticleActivity>() articleIntent.putExtras(intent) TaskStackBuilder.create(this).addNextIntent(intentFor<DrawerActivity>()).addNextIntent(articleIntent).startActivities() } } Crashlytics的例外 java.lang.NullPointerException at android.os.Parcel.readException(Parcel.java:1471) at android.os.Parcel.readException(Parcel.java:1419) at android.app.ActivityManagerProxy.startActivities(ActivityManagerNative.java:4473) at android.app.Instrumentation.execStartActivitiesAsUser(Instrumentation.java:1496) at android.app.ContextImpl.startActivitiesAsUser(ContextImpl.java:1417) at android.content.ContextWrapper.startActivitiesAsUser(ContextWrapper.java:356) at android.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:221) at android.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:232) at android.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:208) at se.omni.gcm.OpenArticleService.onHandleIntent(OpenArticleService.kt:27) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.os.HandlerThread.run(HandlerThread.java:61)

以完整的长度截图RecyclerView

我想获得该活动的“完整页面”屏幕截图。 该视图包含许多项目的RecyclerView。 我可以用这个函数截取当前视图的截图: public Bitmap getScreenBitmap() { View v= findViewById(R.id.container).getRootView(); v.setDrawingCacheEnabled(true); v.buildDrawingCache(true); Bitmap b = Bitmap.createBitmap(v.getDrawingCache()); v.setDrawingCacheEnabled(false); // clear drawing cache return b; } 但它只包含我可以正常查看的项目(如预期)。 有没有什么办法可以让RecyclerView以全屏的方式神奇地显示出来(一次显示所有的项目)? 如果不是,我该如何处理这个问题?

监听器绑定; 找不到Setter

我想实现监听器绑定 ,但是当我运行我的代码时,我得到以下错误: Caused by: android.databinding.tool.util.LoggedErrorException: Found data binding errors. ****/ data binding error ****msg:Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.Button. file:~/GithubBrowser/app/src/main/res/layout/loading_state.xml loc:30:31 – 30:52 ****\ data binding error **** 这是有问题的布局文件: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <import type="com.example.app.data.model.Resource"/> <import type="com.example.app.data.model.Status"/> <variable name="resource" type="Resource"/> <variable name="callback" type="com.example.app.ui.common.RetryCallback"/> </data> <LinearLayout […]

Kotlin高阶函数如何工作?

为了理解高阶函数以及如何将函数作为参数传递给使用Kotlin的其他函数,我正在苦苦挣扎。 我有一个基本的例子,我想填补: fun addOnSearchGameResultListener( activity: AppCompatActivity, releaseThread: () -> Unit, showNoResultsFoundMessage: () -> Unit, updateSearchResults: (result: List<Game>) -> Unit) { var event0017Handler: TaskExecutor = object : TaskExecutor { override fun executeOnSuccessTask(response: JSONObject) { async() { uiThread { try { releaseThread() mLoaderManager.hideIndeterminateProgressBar(activity) val result = mJSONParser.getGamesByGameKey(response) Log.i(GameController::class.simpleName, "response: ${result.toString()}") updateSearchResults(result) } catch (e: JSONException) { showNoResultsFoundMessage() […]

KotterKnife – 对某些类不能使用bindView(R.id.example_id)

尝试使用KotterKnife时出现以下错误 – 但只适用于某些类。 这是怎么回事? e: /Users/user/dev/git/to14/android/src/main/kotlin/com.example/adapters/ChapterListAdapter.kt: (59, 34): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public fun <T : android.view.View> android.app.Dialog.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.support.v4.app.Fragment.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.app.Fragment.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> […]

在kitkat设备上开始活动

尝试使用context.startActivity(intent)打开活动时会引发这种情况 java.lang.TypeNotPresentException: Type android/support/v4/app/ActivityCompat$SharedElementCallback23Impl not present 所有的活动扩展AppCompatActivity ,我在我的应用程序的静态块内调用AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) 。 在较新的Android版本everyting是好的。 有人遇到这个问题,可以分享如何解决它的信息? 在这里我的gradle配置 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { lintOptions { disable 'RestrictedApi' } signingConfigs { release { keyAlias '****' keyPassword '*************' storeFile file('../release.jks') storePassword '*************' } } compileSdkVersion 26 buildToolsVersion "26.0.2" defaultConfig { applicationId "***.****" minSdkVersion 19 targetSdkVersion 26 versionCode […]

Android不确定ProgressBar不显示

我正在为我的Android应用程序添加一个旋转进度视觉,为了使它变得复杂,我目前只在我的onCreate中启动它,而不是结束它,因为它应该是非常简单的。 但是,遵循指定只包含进度条的正式Android文档 <ProgressBar android:id="@+id/weather_loading_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 对于不确定的加载条,它不起作用。 我试图增加indeterminate和visibility ,但没有运气。 <ProgressBar android:id="@+id/weather_loading_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="true" android:visibility="visible" /> 我使用Kotlin的Android扩展,所以在我的onCreate()我试过了 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //setVisibility here doesn't actually get shown as an option in the autocomplete, but still compiles. weather_loading_bar.setVisibility(View.VISIBLE) } 但是当我的应用程序启动时,没有进度条。 编辑:这是整个activity_main布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ui.MainActivity"> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/currentData" android:layout_width="match_parent" android:layout_height="wrap_content" […]

Java Int到Float来获得1f为1

如何将Integer或String数字转换为像这样的"1"到1.0f (或1f )的float 。 我尝试了大部分的代码,但是所有的时候我都一样。 但是,我需要得到1f 。 val num = 1 val b = num.toFloat() Log.i("b",b.toString()) 结果是1.0 。

如何运行Google Map?

我究竟做错了什么? 我字面上使用提供的模板为谷歌地图。 public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { /** Templated provide by google */} 我有一个项目的API密钥。 但是,当我运行它,这是我的错误: Error:Gradle: Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process'command'/Library/Java/JavaVirtualMachines/jdk1.8.0_101。 jdk / Contents / Home / bin / java''以非零的退出值2结束 其他错误: Information:Gradle: Executing tasks: [:app:assembleDebug] Information:Kotlin: Kotlin JPS plugin is disabled Gradle文件: apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "24.0.2" […]