小编vih*_*kat的帖子

使用布尔泛型的Kotlin继承

当我尝试使用Boolean,Double,Integer,Float覆盖泛型方法时,我遇到了问题.它适用于Date.(可能因为它是Serializable吗?)

界面:

interface AnInterface<C, T> {
    fun doSomething(items: List<T>, vararg value: C): List<T>
}
Run Code Online (Sandbox Code Playgroud)

一个抽象的实现:(没有覆盖doSomething)

abstract class BaseClass<C, T> : AnInterface<C, T> { ... }
Run Code Online (Sandbox Code Playgroud)

这是工作:

class AnImplementetion<T> : BaseClass<Date, T>() {

    override fun doSomething(items: List<T>, vararg value: Date): List<T> {
            // It works
    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用:

class AnAnotherImplementetion<T> : BaseClass<Boolean, T>() {

    override fun doSomething(items: List<T>, vararg value: Boolean): List<T> {
            // It doens't
    }
}
Run Code Online (Sandbox Code Playgroud)

IDE总是希望实现doSomething.当我用IDE实现它时,它总是创建相同的.

错误信息:

Class 'AnAnotherImplementetion' is not abstract and does not implement abstract base …
Run Code Online (Sandbox Code Playgroud)

android kotlin

9
推荐指数
1
解决办法
288
查看次数

Kotlin使用Java回调接口

我有一个WebView.我想打电话

public void evaluateJavascript(String script, ValueCallback<String> resultCallback)
Run Code Online (Sandbox Code Playgroud)

这种方法.

这是ValueCallback接口:

public interface ValueCallback<T> {
    /**
     * Invoked when the value is available.
     * @param value The value.
     */
    public void onReceiveValue(T value);
};
Run Code Online (Sandbox Code Playgroud)

这是我的kotlin代码:

webView.evaluateJavascript("a", ValueCallback<String> {
            // cant override function
        })
Run Code Online (Sandbox Code Playgroud)

有人想知道在kotlin中覆盖onReceiveValue方法吗?我尝试了"将Java转换为Kotlin",但结果是下一个:

v.evaluateJavascript("e") {  }
Run Code Online (Sandbox Code Playgroud)

谢谢!

kotlin kotlin-interop

6
推荐指数
2
解决办法
6236
查看次数

带有参数的导航组件.popBackStack()

我有两个片段。SecondFragmentThirdFragment。实际上,我使用导航组件在片段之间传递值。像这样:

SecondFragment

val action = SecondFragmentDirections.action_secondFragment_to_thirdFragment().setValue(1)

Navigation.findNavController(it).navigate(action)
Run Code Online (Sandbox Code Playgroud)

这是我从ThirdFragment读取值的方式

 arguments?.let {
           val args = ThirdFragmentArgs.fromBundle(it)
           thirdTextView.text = args.value.toString()
       }
Run Code Online (Sandbox Code Playgroud)

很好 现在我的堆栈看起来像这样:

ThirdFragment

SecondFragment 
Run Code Online (Sandbox Code Playgroud)

是否可以通过新的导航组件将值从打开的ThirdFragment传递到先前的SecondFragment?(当ThirdFragment完成时)

我知道onActivityResult,但是如果Nav.Component提供比我想要的更好的解决方案。

谢谢!

android android-fragments android-architecture-navigation

6
推荐指数
2
解决办法
1416
查看次数

TextInputLayout 的布局膨胀缓慢

我有一个自定义视图,它扩展自LinearLayout. 在init{}我调用该inflate函数来膨胀我的布局。

inflate(context, R.layout.base_layout, this)
Run Code Online (Sandbox Code Playgroud)

我记录了充气速度,如下所示:

// Log.
inflate(context, R.layout.base_layout, this)
// Log
Run Code Online (Sandbox Code Playgroud)

需要1ms膨胀布局。惊人的!但是当我的布局有一个 TextInputLayout 时,它会增加到120ms

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/randomName2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/randomName"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

        <android.support.design.widget.TextInputLayout
            android:id="@+id/randomName4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:paddingTop="8dp">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/randomName3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text" />

        </android.support.design.widget.TextInputLayout>


    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/randomName"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginBottom="4dp"
        android:gravity="bottom"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="@id/randomName2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@id/randomName2"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个120ms问题?这会在我的片段创建时造成 FPS 延迟。

感谢您的任何建议。

android

5
推荐指数
0
解决办法
819
查看次数

具有Firestore实时数据的RxJava

我有存储库类。在这些课程中,我这样简单collection("..").get()

override fun getTestCollectionItems(): Observable<TestModel> {

    return Observable.create { subscriber ->

        firebaseFirestore.collection(TEST_COLLECTION)
                .get()
                .addOnCompleteListener { task ->

                    if (task.isSuccessful()) {
                        for (document in task.getResult()) {
                            if (document.exists()) {
                                val documentModel = document.toObject(TestModel::class.java)
                                subscriber.onNext(documentModel)
                            }
                        }
                        subscriber.onComplete()
                    } else {
                        subscriber.onError(task.exception!!)
                    }
                }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我找到了实时Firecloud选项。如果我将侦听器移至存储库,那么它的含义是否正确?

我尝试了下一个:

override fun getRealTimeCollection() : Observable<TestModel> {

    return Observable.create { subscriber ->

        firebaseFirestore.collection(TEST_COLLECTION).document("3lPtYZEEhPdfvZ1wfHIP")
            .addSnapshotListener(EventListener<DocumentSnapshot> { snapshot, e ->
                if (e != null) {
                    Log.w("test", "Listen failed.", e)
                    subscriber.onError(e)
                    return@EventListener
                }

                if (snapshot != …
Run Code Online (Sandbox Code Playgroud)

android rx-java2

2
推荐指数
1
解决办法
1558
查看次数

Codeigniter 删除 ... 哪里 ... 和

我需要一点帮助。如何使用 codeigniter 发送此查询?

Delete FROM friendconnect WHERE who = 5 and whos = 1 OR whos = 5 and who = 1;
Run Code Online (Sandbox Code Playgroud)

我发现只有:

$this->db->where('id', $id);
$this->db->delete('mytable'); 
Run Code Online (Sandbox Code Playgroud)

谢谢大家!

php sql codeigniter sql-delete

1
推荐指数
1
解决办法
8939
查看次数

RxJava - 链式调用

我有两种方法。让它看到第一个的模型。

open class CommentModel {
    var postid: String? = null
    var ownerid: String? = null
    var created: Date? = null
    var message: String? = null

    constructor() {
    }

    constructor(postid: String?, ownerid: String?, message: String?, created: Date?) {
        this.ownerid = ownerid
        this.created = created
        this.postid = postid
        this.message = message
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个模型中。我有ownerid。我需要开始一个新的调用来获取所有者的 UserModel。

所以:

   commentRepository.getPostCommentsById(postId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    { commentModel ->
                    // it = the owner of comment.
                        userRepository.getUserDetailsByUid(commentModel.ownerid!!)
                                .subscribeOn(Schedulers.io())
                                .observeOn(AndroidSchedulers.mainThread())
                                .subscribe(
                                        { userModel ->
                                            val comment = CommentWithOwnerModel(commentModel,usermodel)
                                            view.loadComment(comment) …
Run Code Online (Sandbox Code Playgroud)

android kotlin rx-java2

1
推荐指数
1
解决办法
745
查看次数