Android 未为所有项调用适配器getView()
我有一个由自定义适配器支持的列表视图。适配器的项列表中有17项,但仅显示前2项。我通过Android 未为所有项调用适配器getView(),android,Android,我有一个由自定义适配器支持的列表视图。适配器的项列表中有17项,但仅显示前2项。我通过getView()进行了跟踪,并确认只对位置0和1调用了它 填充适配器并在父级活动的onCreate()中进行设置 FavouritesListAdapter adapter = new FavouritesListAdapter(favourites, this); ((ListView) findViewById(R.id.list)).setAdapter(adapter); adapter.notif
getView()
进行了跟踪,并确认只对位置0和1调用了它
填充适配器并在父级活动
的onCreate()
中进行设置
FavouritesListAdapter adapter = new FavouritesListAdapter(favourites, this);
((ListView) findViewById(R.id.list)).setAdapter(adapter);
adapter.notifyDataSetChanged(); // not needed but put here out of desperation!
适配器签名和getView()
方法:
public class FavouritesListAdapter extends BaseAdapter {
private Context context;
private ArrayList<Favourite> entries;
public FavouritesListAdapter(ArrayList<Favourite> favourites, Context context) {
this.entries = favourites;
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout rl;
Log.d(LOG_DEBUG_TAG, "Count:" + getCount() ", asking for pos " + position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rl = (RelativeLayout) inflater.inflate(R.layout.favourite_tide_table, null);
convertView = rl;
} else { // convertView is not null (it's being recycled)
Favourite thisFavourite = this.getItem(position);
convertView = thisFavourite.getPortView();
}
return convertView;
}
活动XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:background="@color/white"
android:cacheColorHint="#00000000"
android:divider="#FF0000"
android:dividerHeight="1px"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</ScrollView>
前两项正确显示
我错过了什么?谢谢 A
ListView
无法进入ScrollView
看看罗曼·盖伊。谷歌I/O视频中的更多细节
如果您真的需要将
列表视图
放在滚动视图
中,您基本上需要列表视图
知道它的高度,这可以使用DougW回答上述问题。屏幕上有多少行不要将列表视图放在滚动视图中。它不起作用。@njzk2-Doh,Doh,Doh!我真不敢相信那是多么愚蠢!我完成了多少列表视图?谢谢如果你想要这个代表,请把你的评论作为一个答案(这对未来的访问者是好的),我会接受的。干杯
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:background="@color/white"
android:cacheColorHint="#00000000"
android:divider="#FF0000"
android:dividerHeight="1px"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</ScrollView>