【问题标题】:Android ListView not displaying more than 8 digitsAndroid ListView 不显示超过 8 位数字
【发布时间】:2013-01-31 20:00:35
【问题描述】:

我正在将警报中的毫秒数存储到数据库中,并且数据库已正确存储它们,因为我测试它在单个 TextView 中显示它们并显示它们全部。但是我的 ListView 只显示有 8 个数字的毫秒值,当有 9 个或更多数字时,它不会显示它们。这是我的列表视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="250dp" >

    </ListView>

</LinearLayout>

我用于行的 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text1"
        android:layout_width="match_parent"        
        android:gravity="center"
        android:layout_height="45dp" />

</LinearLayout>

我用于填充 ListView 的方法:

private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = DatabaseManager.getAllData();
        startManagingCursor(c);

        String[] from = new String[] { DatabaseManager.TABLE_COLUMN_TWO };
        int[] to = new int[] { R.id.text1 };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
        setListAdapter(notes);
    }

【问题讨论】:

  • 不显示还是只显示9位以上的8位?
  • @Simon 显示 8 位或更少,9 或更多根本不显示,如果它的 9 位或更多位,则不会显示整数(行)。好像根本不存在(但在数据库里)
  • @Simon 因此,如果它的数字为 8 位或更少,它将显示在 ListView 的行中,但如果它的数字为 9 位,则不会填充到 ListView 中。
  • 这很奇怪。我会尝试编写自己的适配器并进行测试。 blog.cluepusher.dk/2009/11/16/…

标签: java android database listview


【解决方案1】:

请将 Listview 替换为以下代码。 
它运行良好。
不要在 android:layout_height 中修复 Listview 的高度
请将您的布局 xml 代码替换为以下 xml。

&lt?xml version="1.0" encoding="utf-8"?>
&ltLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

&ltListView
android:id="@android:id/list "
android:layout_width="match_parent"
android:layout_height="match_parent" >
&lt/ListView>

&lt/LinearLayout>

【讨论】:

  • 感谢您的建议,但它不起作用。尝试在 3.2 英寸 (320x480) 屏幕上进行测试,您会发现它不起作用。它适用于较大的屏幕,但不适用于较小的屏幕。
  • 我在不同的设备上进行了测试。它工作正常。你使用的是什么版本,你能附上屏幕截图吗?您是在模拟器还是移动设备上进行测试?
猜你喜欢
  • 2015-07-09
  • 2017-07-24
  • 2012-08-21
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
  • 2017-05-09
  • 2012-09-27
  • 1970-01-01
相关资源
最近更新 更多