手动将数据插入Firebase数据库,并在我的android应用程序中显示为ListView
我正在尝试使用Firebase实时数据库为我的android应用程序创建校友数据库。我想手动从Firebase控制台插入数据。现在我的第一个问题是如何做到这一点(一个数据库的示例结构会很有帮助)。我的数据库有3个字段(姓名、职务和工作场所) 其次,在添加数据后,我如何在我的应用程序中将它们显示为ListView。我还想为我的数据库添加一个过滤器选项。我已经创建了模型类和列表布局 校友班:手动将数据插入Firebase数据库,并在我的android应用程序中显示为ListView,listview,firebase-realtime-database,Listview,Firebase Realtime Database,我正在尝试使用Firebase实时数据库为我的android应用程序创建校友数据库。我想手动从Firebase控制台插入数据。现在我的第一个问题是如何做到这一点(一个数据库的示例结构会很有帮助)。我的数据库有3个字段(姓名、职务和工作场所) 其次,在添加数据后,我如何在我的应用程序中将它们显示为ListView。我还想为我的数据库添加一个过滤器选项。我已经创建了模型类和列表布局 校友班: public class Alumni { String name = null; Str
public class Alumni {
String name = null;
String designation = null;
String workplace = null;
public Alumni(String name, String designation, String workplace) {
this.name = name;
this.designation = designation;
this.workplace = workplace;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getWorkplace() {
return workplace;
}
public void setWorkplace(String workplace) {
this.workplace = workplace;
}
@Override
public String toString() {
return name + " " + designation + " " + workplace;
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
android:padding="5dp">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/icon_work"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:contentDescription="@string/icon_work"
android:src="@drawable/icon_workplace"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:textSize="12sp"
android:textColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/icon_work"
app:layout_constraintStart_toEndOf="@id/icon_work"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:text="@string/bar"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/designation"
app:layout_constraintStart_toEndOf="@+id/designation"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/workplace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:textColor="@color/colorPrimary"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/bar"
app:layout_constraintTop_toBottomOf="@+id/name" />
</androidx.constraintlayout.widget.ConstraintLayout>
list\u row.xml:
public class Alumni {
String name = null;
String designation = null;
String workplace = null;
public Alumni(String name, String designation, String workplace) {
this.name = name;
this.designation = designation;
this.workplace = workplace;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getWorkplace() {
return workplace;
}
public void setWorkplace(String workplace) {
this.workplace = workplace;
}
@Override
public String toString() {
return name + " " + designation + " " + workplace;
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
android:padding="5dp">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/icon_work"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:contentDescription="@string/icon_work"
android:src="@drawable/icon_workplace"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:textSize="12sp"
android:textColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/icon_work"
app:layout_constraintStart_toEndOf="@id/icon_work"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:text="@string/bar"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/designation"
app:layout_constraintStart_toEndOf="@+id/designation"
app:layout_constraintTop_toBottomOf="@+id/name" />
<TextView
android:id="@+id/workplace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:textColor="@color/colorPrimary"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/bar"
app:layout_constraintTop_toBottomOf="@+id/name" />
</androidx.constraintlayout.widget.ConstraintLayout>
关于这类示例的文章链接将很有帮助