Android Firebase 列表适配器构造函数错误

Android Firebase List Adapters Constructor Error

我正在尝试使用来自 Firebase 的实时数据创建一个列表视图 database.For 由于某些原因我一直在这条线下面看到一条红线 code.Hope 你可以告诉我什么是我的错误在这里。谢谢 :)。我附上了我的布局文件和我的应用程序 gradle 代码。

(this,String.class,android.R.layout.simple_list_item_1,databaseReference)

Below here is the complete code

            DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://vsem-inventory.firebaseio.com/");
        FirebaseListAdapter<String> firebaseListAdapter = new FirebaseListAdapter<String>(this,String.class,android.R.layout.simple_list_item_1,databaseReference) {
            @Override
            protected void populateView(@NonNull View v, @NonNull String model, int position) {
                TextView textView = v.findViewById(android.R.id.text1);
            }
        };

        mListView.setAdapter(firebaseListAdapter);

content_main_menu.xml

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainMenu">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="0dp" />
</RelativeLayout>

应用程序 gradle

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.user.vseminventory"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.firebase:firebase-client-android:2.3.1'
    implementation 'com.firebaseui:firebase-ui-database:4.3.0'
}

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

看来您使用的是新的 Firebaseui(版本 3.0+),FirebaseListAdapter 的构造函数已更改。

首先,您需要使用 class FirebaseListOptions 配置适配器,然后您可以创建 FirebaseListAdapter.

的实例

从文档中检查这段代码:

 FirebaseListOptions<Chat> options = new FirebaseListOptions.Builder<Chat>()
    .setQuery(query, Chat.class)
    .build();

FirebaseListAdapter<Chat> adapter = new FirebaseListAdapter<Chat>(options) {
@Override
protected void populateView(View v, Chat model, int position) {
    // Bind the Chat to the view
    // ...
 }
};

如您所见,FirebaseListAdapter 采用类型为 FirebaseListOptions

的参数

更多信息在这里:

https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#using-firebaseui-to-populate-a-listview


你可以在这里查看源代码:

https://github.com/firebase/FirebaseUI-Android/blob/master/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java