gpt4 book ai didi

android 我的 ListView 不显示所有项目

转载 作者:行者123 更新时间:2023-11-29 18:35:15 25 4
gpt4 key购买 nike

我的 ListView 从我的 firebase 获取数据时出现问题。它仅显示 8,5 个项目而不是 11 个项目。我不知道问题是在 xml 中还是在我的代码中。我知道它在 j 变量中获取 11 条记录,但它在我的屏幕上显示 8 条半。

ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
ArrayList<String> array = new ArrayList<>();
array.clear();
int j=0;
for(DataSnapshot ds : dataSnapshot.getChildren()) {
Fall fall = ds.getValue(Fall.class);
array.add("Date: " + fall.getDate() + "\n" + "Time: " + fall.getTime() + "\n" + "Location: " + fall.getLocation());
j++;
}

ArrayAdapter<String> adapter2 = new ArrayAdapter<>(History.this, android.R.layout.simple_list_item_1, array);
l1.setAdapter(adapter2);
//setListViewHeight(l1);
Toast.makeText(getApplicationContext(),String.valueOf(j), Toast.LENGTH_LONG).show();

}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("FallAppError: ", databaseError.getMessage()); //errors!
}
};



uidRef.addListenerForSingleValueEvent(valueEventListener);
historyTextView.setText("Ιστορικό του/της \n" + setupDisplayName());

}

这是我的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@mipmap/background"
android:orientation="vertical"
tools:context="com.zouve.fallapp.LoginActivity">


<TextView
android:id="@+id/historyTextView"
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="Ιστορικό"
android:textColor="@color/green"
android:textSize="25sp"
android:textStyle="bold" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<ListView
android:id="@+id/historyListView"
android:layout_width="match_parent"
android:layout_height="571dp"
android:layout_weight="1" />

</LinearLayout>
</ScrollView>

有什么想法吗?提前致谢?

最佳答案

ListViewlayout_height 设置为 wrap_content 而不是硬编码值。

此外,@Vladyslav Matviienko 是对的,您不需要将 ScrollView 作为 ListView 的父级,因为 ListView 已经包含了默认情况下的滚动功能。

注意:建议您改用RecyclerView。快多了!列表的推荐 View !

关于android 我的 ListView 不显示所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54645276/

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