我想子类化Preference以在 Kotlin 中创建自定义首选项。我无法让自定义首选项在首选项屏幕中膨胀。如果我从我的首选项屏幕中删除这个自定义首选项,我实现的其余首选项(此处未显示)工作正常。 还有很多类似的表面上的问题在这里,但没有那些我已经找到了直接处理创建科特林实现自定义偏好的问题。
请帮助我提供一个您已经测试过的工作示例,该示例显示了三件事:
custom_preference.xmlCustomPreference.ktpreference_screen.xml (显示自定义首选项的父首选项屏幕)这是我的代码:一个xml显示字符串的自定义首选项(让我们在示例中保持简单,尽管我的首选项最终会具有更多的功能)
custom_preference.xml
<Preference
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CustomPreference">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a custom preference" />
</Preference>
Run Code Online (Sandbox Code Playgroud)
一个扩展Preference并包含适当构造函数的类。
自定义首选项.kt
package com.example.myApp
import android.content.Context
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceViewHolder
import android.util.AttributeSet
import com.example.myApp.R
import com.example.myApp.R.layout.custom_preference
class CustomPreference (context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.preferenceStyle,
defStyleRes: Int = defStyleAttr)
: Preference(context, attrs, defStyleAttr, defStyleRes) {
override …Run Code Online (Sandbox Code Playgroud) android android-preferences preferencescreen kotlin android-recyclerview
在我的Android应用程序中,我使用rest模板进行服务调用,但问题是现在我在调用任何服务时遇到错误.服务未连接到服务器.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lss.company, PID: 8611
java.lang.NoClassDefFoundError: org.springframework.web.util.UriTemplate
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:498)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:447)
at com.lss.company.services.ServerAuthenticateService.getAllEmployeeList(ServerAuthenticateService.java:7320)
at com.lss.company.view.LoginActivity.onCreate(LoginActivity.java:138)
at android.app.Activity.performCreate(Activity.java:5459)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5598)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
下面是build.gradle依赖项代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.lss.company"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
lintOptions …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行自动更新功能,经过大量搜索后,我找到了从服务器下载 .apk 文件到我的设备的解决方案,但我无法启动此文件,提示用户安装的窗口打开但关闭直接的。
这是我的代码
Java.IO.File file = new Java.IO.File(destination);
Android.Net.Uri apkURI = Android.Support.V4.Content.FileProvider.GetUriForFile(
_context,
_context.ApplicationContext.PackageName + ".provider", file);
Intent promptInstall = new Intent(Intent.ActionView);
//promptInstall.SetDataAndType(apkURI, "application/vnd.android.package-archive");
promptInstall.SetData(apkURI);
promptInstall.AddFlags(ActivityFlags.NewTask);
promptInstall.AddFlags(ActivityFlags.GrantReadUriPermission);
_context.GrantUriPermission(_context.ApplicationContext.PackageName, apkURI, ActivityFlags.GrantReadUriPermission);
_context.StartActivity(promptInstall);
Run Code Online (Sandbox Code Playgroud)
我尝试了很多标志和 Ident.Action 的组合,例如 ActionInstallPackage
安卓版本是8.1
谢谢
更新:解决了一个问题:现在updateList解决了,问题是我定义mAdapter为RecyclerView.Adapter而不是MyAdapter。但是现在即使我正在获取数据,列表上也没有任何显示,它是空的
-------------------- 原始帖子 --------------------
我想更新我的RecyclerView用法DiffUtil以防止重复。
我有4个类:User类,Activity设置数据的Adapter类,类和DiffUtil类。我不确定我是否正确组合了所有这四个。
这是User类:
public class User {
private String mUserId;
private Uri mImageUrl;
public User(String userId, String imageUrl) {
mUserId = userId;
mImageUrl = Uri.parse(imageUrl);
}
public String getUserId() {
return mUserId;
}
public Uri getImageUrl() {
return mImageUrl;
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我动态设置数据的方式(我不断Json从服务器上获取要显示的包含用户ID的新数组,然后从Firebase存储中设置用户图像):(这是一个由onClick侦听器调用的函数:)
这是片段中的方法调用:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
updateUsersList();
} …Run Code Online (Sandbox Code Playgroud) java android recycler-adapter android-recyclerview android-diffutils
我有一个名为“容器” 的LinearLayout内部DrawerLayout。在运行时,我正在尝试RelativeLayout在“容器”中添加一个容器。这会导致RelativeLayout对齐无法正常运行,即进度超过徽标图像。
相对布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:keepScreenOn="true">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingEnd="5dp">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:visibility="gone" />
<TextView
android:id="@+id/tv_network_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center"
android:text="@string/no_network"
android:textColor="#E10000"
android:textSize="30sp"
android:visibility="visible" />
</LinearLayout>
<TextView
android:id="@+id/tv_software_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:paddingRight="20dp"
android:paddingBottom="20dp"
android:text="Version"
android:textColor="@android:color/darker_gray" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
具有容器的DrawerLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"> …Run Code Online (Sandbox Code Playgroud) 我正在使用翻新版本2.6.1通过网络发出http请求。我期望的JSON长42466个字符。但是,我只收到4073个字符,并且API在Web浏览器和邮递员上正常工作。
因此,我添加了自定义okhttp客户端并增加了超时时间,但这对我没有帮助。
private var okHttpClient: OkHttpClient = OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.build()
Run Code Online (Sandbox Code Playgroud)
然后,我尝试添加一个日志记录拦截器,发现okhttp在拦截器日志中以块的形式接收了我想要的响应。
private val httpInterceptor: HttpLoggingInterceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
private var okHttpClient: OkHttpClient = OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.addInterceptor(httpInterceptor)
.build()
Run Code Online (Sandbox Code Playgroud)
最后,我将http客户端和拦截器分配给改造生成器,这就是它的外观
private val centralRetrofit = Retrofit.Builder().baseUrl("https://www.********.com/")
.addConverterFactory(ScalarsConverterFactory.create())
.client(okHttpClient)
.build()
.create(MusicAccess::class.java)
Run Code Online (Sandbox Code Playgroud)
因此,我认为使用发布请求将对我有所帮助,而不是尝试以字符串格式获取所有响应以检查响应
@Headers("Content-Type: text/html; charset=UTF-8")
@POST("**********")
fun getMusic(): Call<String>
Run Code Online (Sandbox Code Playgroud)
但是在我认为http响应将具有大小限制并使用阅读器通过以下方式从url访问json之后,也没有得出结论。
val client = OkHttpClient()
val request = Request.Builder().url("********")
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()
val input = response.body()?.byteStream()
val reader = BufferedReader(InputStreamReader(input)) …Run Code Online (Sandbox Code Playgroud) 我有一个带有以下注释的单元测试:
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = TestConfiguration.class)
@TestPropertySource("classpath:application-test.properties")
Run Code Online (Sandbox Code Playgroud)
我使用 Spring Boot 2.2.0 和 Spring 5.2.0 以及 Junit Jupiter。该测试使用内存中的 H2 数据库测试 dao 类。在我切换到 Spring Boot 2.2.0 之前,这曾经有效。我收到一个错误
java.lang.NoSuchFieldError: IMPORT_BEAN_NAME_GENERATOR
Run Code Online (Sandbox Code Playgroud)
当我调试时,我看到
@Override
@Deprecated
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
registerBeanDefinitions(metadata, registry, ConfigurationClassPostProcessor.IMPORT_BEAN_NAME_GENERATOR);
}
Run Code Online (Sandbox Code Playgroud)
在类 RepositoryBeanDefinitionRegistrarSupport 中。我在registerBeanDefinitions. 该方法已弃用,文档说它被替换为具有三个参数的方法here。当我在定义的ConfigurationClassPostProcessor位置设置断点时IMPORT_BEAN_NAME_GENERATOR,代码不会到达那里。显然,有些东西正在使用旧方法,但我不知道是什么。当我回到 spring boot 2.1.8 时,我没有收到此错误。
我在Android Studio中搜索文本,可以看到图像A
我发现搜索结果包含自动生成代码,例如LayoutHomeBindingImpl
我希望从自动生成代码中排除搜索结果,我该怎么办?
图片A

我有一个具有这种层次结构的布局
< NestedScrollView fillViewPort=true>
< LinearLayout>
< Viewgroup/>
< ViewGroup/>
< RecyclerView/>
< ViewGroup/>
</LinearLayout>
</NestedScrollView>
有时我需要更新我的 recyclerview 元素,但它会冻结主线程。我的猜测是因为滚动视图需要再次测量它。我真的很想知道我应该怎么做?
我目前正在构建一个应用程序,该应用程序创建了一个用户可以在网络上共享信息的平台,但我想创建一个离线选项,让用户在近距离时仍然可以在对等网络上进行通信。是否可以使用智能手机创建 BT 网状网络?
我已经看到蓝牙可以选择使用 BLE 创建网状网络,但是在研究 CoreBluetooth 之后,我找不到任何支持这种类型网络的东西。我已经看到了一些使用 iOS Multipeer 连接的解决方案,但如果可能的话,我最喜欢跨平台解决方案。
android ×9
java ×2
spring-boot ×2
apk ×1
installation ×1
ios ×1
kotlin ×1
okhttp ×1
resttemplate ×1
retrofit ×1
retrofit2 ×1
spring ×1
xamarin ×1