gpt4 book ai didi

Android List + Adapter 仅显示第一个条目

转载 作者:太空狗 更新时间:2023-10-29 15:39:15 24 4
gpt4 key购买 nike

所以我制作了一个自定义 ArrayAdapter 来填充我的列表,它只是覆盖了 getView(int position, View v, ViewGroup parent)。

如果我这样使用它:

public class MyActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(adapter);
}
}

一切正常,我的列表正确显示了所有条目。

现在,如果我尝试在 XML 布局中的 上使用相同的适配器类,如下所示:

ListView lv = (ListView) v.findViewById(R.id.list);
MyAdapter a = new MyAdapter (lv.getContext(), R.layout.list_item, entries);
lv.setAdapter(a);

它只显示列表的第一个条目。

我已经尝试使用 adapter.add(entry.get(i)); 手动添加项目;并调用 adapter.notifyDataSetChanged();之后这没有帮助。

e:这是 XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1dp">

<TextView
android:id="@+id/bc_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"/>

<TextView
android:id="@+id/bc_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@drawable/title_gradient"/>

<TextView
android:id="@+id/bc_genre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:background="@drawable/location_gradient"
android:textColor="#ffffff"/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="0.4"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp">
<ImageButton
android:id="@+id/bc_homepage"
android:src="@drawable/homepage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="loadWebsite"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
<ImageButton
android:id="@+id/bc_facebook"
android:src="@drawable/facebook"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="loadWebsite"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
<ImageButton
android:id="@+id/bc_myspace"
android:src="@drawable/myspace"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="loadWebsite"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
<ImageButton
android:id="@+id/bc_fav"
android:src="@drawable/d_attends"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".1"
android:padding="0dp"
android:onClick="favBand"
android:background="@drawable/black_button"
android:layout_margin="2dp"
/>
</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"/>

</LinearLayout>

最佳答案

我认为您不应该在 scrollView 中使用 ListView,因为内置的 ListView 提供了滚动功能。在上面的代码中,由于在线性布局中垂直添加所有 View ,因此您的 ListView 位于底部,因此根是 ScrollView, ListView 的自动 ScrollView 选项无法向您显示所有条目。考虑一下并尝试在 ScrollView 之外添加 ListView。

关于Android List + Adapter 仅显示第一个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10318826/

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