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

时间:2019-02-12 07:57:29

标签: android 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>

有什么想法吗? 预先感谢?

1 个答案:

答案 0 :(得分:2)

layout_height中的ListView改成wrap_content,而不是硬编码值。

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