ListView不会自动滚动

时间:2014-08-15 13:08:31

标签: android listview

我的ListView不会自动滚动,所以如果有多个项目我无法访问它(id不适合屏幕)。我认为这是关于我的xml文件。我在本主题中找到的大多数答案都是关于列表视图和滚动条的情况。我试图这样做,但没有结果。你能告诉我错误在哪里吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".Main">

        <EditText
            android:id="@+id/getName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <EditText
            android:id="@+id/getDuration"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <Button
            android:id="@+id/button"
            android:text="Send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="send"/>

        <Button
            android:id="@+id/getListButton"
            android:text="getList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="getVideoList"/>

    <ListView
        android:id="@+id/videoList"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="vertical">
    </ListView>

</LinearLayout>

正如G. Blake所说,问题可能在我的适配器中。这是连接到它的代码:

List<String> videosNames = new ArrayList<String>();
        for (Video v : videos){
            videosNames.add(v.getTitle());
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1,videosNames);
        videoList.setAdapter(adapter);

2 个答案:

答案 0 :(得分:0)

将其转换为RelativeLayout并将ListView放在所有其他项目下方。像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <EditText
        android:id="@+id/getName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/getDuration"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/getName"/>

    <Button
        android:id="@+id/button"
        android:text="Send"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="send"
        android:layout_below="@id/getDuration"/>

    <Button
        android:id="@+id/getListButton"
        android:text="getList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="getVideoList"
        android:layout_below="@id/button"/>

<ListView
    android:id="@+id/videoList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/getListButton"/>

</RelativeLayout>

将这些其他视图添加到ListView标题中并将ListView作为此布局的一部分可能会更好。

答案 1 :(得分:0)

环境重启后它开始起作用了。感谢所有人的兴趣。