Android 在listview中动态添加项

Android 在listview中动态添加项,android,listview,adapter,Android,Listview,Adapter,我有一个适配器,可以从列表模板加载项。 起初,圣殿骑士有10件物品。当用户滚动到底部时,通过从另一个列表propertyDetailsList获取项目,会自动向tempList添加10个以上的项目 for (int i = 0; i < 10; i++) { tempList.add(propertyDetailsList.get(i)); } propertyDetailsInstantAdapter.notifyDataSetChanged(); for(int i=0;i

我有一个适配器,可以从列表模板加载项。 起初,圣殿骑士有10件物品。当用户滚动到底部时,通过从另一个列表propertyDetailsList获取项目,会自动向tempList添加10个以上的项目

for (int i = 0; i < 10; i++) {
    tempList.add(propertyDetailsList.get(i));
}
propertyDetailsInstantAdapter.notifyDataSetChanged();
for(int i=0;i<10;i++){
add(propertyDetailsList.get(i));
}
propertyDetailsInstantAdapter.notifyDataSetChanged();
但是,结果是只有0处的项(propertyDetailsList.get(0))被添加到tempList,并且它被添加了10次。。。。 我的代码怎么了

更多代码:

private ListView propertyList;
private List<PropertyDetails> tempList;
private List<PropertyDetails> propertyDetailsList;
......
propertyDetailsList = getList();
tempList = propertyDetailsList.subList(0, 10);
......

public void showPropertyList() {
    propertyList.setAdapter(buildPropertyList());
    mIsLoading = false;
    propertyList.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (!mIsLoading && mMoreDataAvailable) {
                if (totalItemCount - visibleItemCount - AUTOLOAD_THRESHOLD <= firstVisibleItem) {
                    mIsLoading = true;
                    for (int i = 0; i < 10; i++) {
                    tempList.add(propertyDetailsList.get(10 + i));
                }
                    propertyDetailsInstantAdapter.notifyDataSetChanged();
                    mIsLoading = false;
                }
            }
        }
    });
}

public InstantAdapter<PropertyDetails> buildPropertyList() {
    propertyDetailsInstantAdapter = new InstantAdapter<PropertyDetails>(
            this, R.layout.property_list_item, PropertyDetails.class, tempList) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            PropertyListItem propertyListItem;
            Context context = parent.getContext();

            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.property_list_item, parent, false);
                propertyListItem = new PropertyListItem();
                propertyListItem.propertyImage = (ImageView) convertView.findViewById(R.id.propertyListImage);
                propertyListItem.propertyAddress = (TextView) convertView.findViewById(R.id.propertyListAddress);
                propertyListItem.propertyName = (TextView) convertView.findViewById(R.id.propertyListName);
                propertyListItem.propertyDetails = this.getItem(position);
                convertView.setTag(propertyListItem);
            } else {
                propertyListItem = (PropertyListItem) convertView.getTag();
            }

            final PropertyDetails propertyDetails = this.getItem(position);
            Transformation transformation = new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {
                    int targetWidth = sp.getInt("deviceWidth", 0);
                    double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
                    int targetHeight = (int) (targetWidth * aspectRatio);
                    Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
                    if (result != source) {
                        // Same bitmap is returned if sizes are the same
                        source.recycle();
                    }
                    return result;
                }

                @Override
                public String key() {
                    return "transformation" + " desiredWidth";
                }
            };
            if (propertyDetails.getImg_link() != null) {
                Picasso.with(context)
                        .load(Uri.parse(propertyDetails.getImg_link()))
                        .transform(transformation)
                        .into(propertyListItem.propertyImage);
            }
            propertyListItem.propertyAddress.setText(propertyDetails.getPropertyAddress());
            propertyListItem.propertyName.setText(propertyDetails.getPropertyName());

            return convertView;
        }
    };
    return propertyDetailsInstantAdapter;
}
私有ListView属性列表;
私人名单圣殿骑士;
私有列表propertyDetailsList;
......
propertyDetailsList=getList();
tempList=propertyDetailsList.subList(0,10);
......
public void showPropertyList(){
setAdapter(buildPropertyList());
错误加载=错误;
propertyList.setOnScrollListener(新的AbsListView.OnScrollListener(){
@凌驾
公共无效onScrollStateChanged(AbsListView视图,int scrollState){
}
@凌驾
public void onScroll(AbsListView视图、int firstVisibleItem、int visibleItemCount、int totalItemCount){
如果(!加载错误(&mMoreDataAvailable){

如果(totalItemCount-visibleItemCount-AUTOLOAD_THRESHOLD什么数据类型是tempList和PropterDetails?您有没有创建过新的PropertyDetails?请告诉我们您是如何创建列表的……对Panther:这些是列表。对AsfK:没有,我只创建了一次propertyDetailsList。对于tempList,它首先包含propertyDetailsList中的前10项。)(tempList=propertyDetailsList.subList(0,10);)。然后,当我滚动到底部时,tempList会展开。我已经检查过,propertyDetailsList包含按正确顺序排列的项目,因此它应该不会显示同一项目10次…@Derekyy,请显示更多代码