【发布时间】:2019-01-02 09:02:32
【问题描述】:
我正在尝试使用 Firebase 实时数据库中的数据创建一个列表视图。出于某种原因,我一直在此代码下看到一条红线。希望您能在这里告诉我我的错误是什么。谢谢 :)。我附上了我的布局文件以及我的应用程序 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>
应用分级
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
【问题讨论】:
-
能否说明遇到的错误
-
它只是说明编译错误
-
请分享整个活动的代码,包括你的gradle
标签: android firebase android-studio firebase-realtime-database android-listview