gpt4 book ai didi

java - 我无法将所有数据从 firebase 获取到我的 Listview

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:17 25 4
gpt4 key购买 nike

我无法将我的数据从 firebase 显示到 Android 应用程序中的 ListView 。相反,它只显示一项数据。这是我数据库的当前数据: Database

这是我的java:

public class scheduleList extends ArrayAdapter<Schedule> {
private Activity context;
private List<Schedule> scheduleList;

public scheduleList(Activity context, List<Schedule> scheduleList){
super(context, R.layout.listlayout, scheduleList);
this.context=context;
this.scheduleList=scheduleList;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listviewItem = inflater.inflate(R.layout.listlayout, null, true);

TextView textViewName = (TextView) listviewItem.findViewById(R.id.textViewName);
TextView textViewSchedule = (TextView) listviewItem.findViewById(R.id.textViewSchedule);

Schedule schedule = scheduleList.get(position);
textViewName.setText(schedule.getAppointer());
textViewSchedule.setText(schedule.getAppointment_schedule());

return listviewItem;
}}

我的java文件:

public class Appointment extends AppCompatActivity {
CalendarView calendarView;
TextView myDate;
private Button btn1;
ListView listViewSchedule;
List<Schedule> scheduleList;
DatabaseReference databaseAppointments;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appointment);
databaseAppointments = FirebaseDatabase.getInstance().getReference("appointment");
calendarView = (CalendarView) findViewById(R.id.calendarView);
myDate = (TextView) findViewById(R.id.myDate);
listViewSchedule=(ListView) findViewById(R.id.listViewSchedule);
scheduleList = new ArrayList<>();
btn1 = (Button) findViewById(R.id.appt);

btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(Appointment.this, appointments2.class);
Appointment.this.startActivity(myIntent);
}
});

calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int i, int i1, int i2) {

String date = (i1 + 1) + "/" + i2 + "/" + i;
myDate.setText(date);
}
});

}
@Override
protected void onStart() {
super.onStart();
databaseAppointments.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
scheduleList.clear();
for(DataSnapshot scheduleSnapshot: dataSnapshot.getChildren()){
Schedule schedule = scheduleSnapshot.getValue(Schedule.class);
scheduleList.add(schedule);
}
scheduleList adapter = new scheduleList(Appointment.this, scheduleList);
listViewSchedule.setAdapter(adapter);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}}

最后是我的包含 ListView 的 xml 文件:

<ScrollView 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cs409.instappoint.Appointment">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/myDate"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select the date"
android:textColor="#ee912a"
android:textAlignment="center"
android:layout_marginStart="125dp"
android:layout_marginTop="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="380dp"
android:layout_marginStart="10dp"
android:layout_gravity="center"
android:layout_height="wrap_content">

<CalendarView
android:id="@+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="320dp">
</CalendarView>
</LinearLayout>

<View
android:layout_width="500dp"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="0dp"
android:background="#ee912a" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointments"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"/>


<ListView
android:id="@+id/listViewSchedule"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<Button
android:id="@+id/appt"
android:layout_width="450dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:layout_marginTop="130dp"
android:background="@drawable/bg_calen"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Appoint now"
android:textColor="#fff" />

</LinearLayout>

我猜测 ScrollView 布局会影响 ListView ,但我不确定。 ListView 也显示列表中的第一个。

最佳答案

使用 FirebaseRecyclerAdapter。搜索如何使用 FirebaseRecylerAdapter 的示例。

关于java - 我无法将所有数据从 firebase 获取到我的 Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48848608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com