我的android列表视图不显示所有项目

问题描述 投票:1回答:1

我有我的ListView一个问题,即是从我的火力点获取数据。它显示的只有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>

有任何想法吗?提前致谢?

android listview
1个回答
2
投票

layout_heightListViewwrap_content,而不是硬编码值。

此外,@Vladyslav Matviienko是正确的,你不需要有ScrollView作为ListView的父母因为ListView已经由默认的滚动功能。

© www.soinside.com 2019 - 2024. All rights reserved.