Android Listview覆盖数据而不是追加

时间:2014-04-27 12:36:50

标签: android listview

在我的Android应用程序中,我使用带有索引值的webservices(例如。

https://mysampleurl.com/sampledata?username=""&&password=""&&startindex="1"&&endindex="10"

并通过BaseAdapter将提取的数据传递给arraylist,并在listview.

中显示结果

listview到达底部时,使用asynctask我会增加索引值(例如。

https://mysampleurl.com/sampledata?username=""&&password=""&&startindex="11"&&endindex="20")

我将收到数据并将其存储在arraylist中,然后继续。

但是当我将数组列表值传递给适配器时,它会覆盖现有数据,而不是附加以前的值。

    @Override
public View getView(final int position, View convertView, ViewGroup parent) 
{
    System.out.println("position:"+position);
}

我在其他一些例子中检查了上面的代码,起初它给出的值如1,2,..... 10。在第二次它给1,2,3,..... 20。但在我的应用程序中,它总是返回值达1,2,3 ...... 10。

有人可以告诉我我做了什么错误吗?

public ContentListAdapter (Context context, ArrayList<CommonData> contentList) 
{
    ctxt = context;
    this.ContentList = contentList;
    contentListRowInflater = LayoutInflater.from(context);
    mSelectedItemsIds=new SparseBooleanArray();
    checkBoxState=new boolean[contentList.size()];
}

    @Override
    public int getCount() {
        return (filteredContentList == null)?0:filteredContentList.size();
    }

    @Override
    public Object getItem(int position) {
        return filteredContentList.get(position);
    }

    @Override
    public long getItemId(int position) 
    {
        return position;
    }

    Here only i pass the values and check the position

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) 
    {
        ContentListActivity.adapterFlag = false;
        DocumentListViewHolder viewHolder = null;
         if (convertView == null || convertView.getTag() == null) {
            convertView = contentListRowInflater.inflate(
                    R.layout.content_list_row, null);
              viewHolder = new DocumentListViewHolder();
            viewHolder.ivDocumentdoctypeIcon = (ImageView) convertView.findViewById(R.id.ivDocumentTypeIcon);
            viewHolder.tvDocumentTitle = (TextView) convertView.findViewById(R.id.tvDocumentTitle);
            viewHolder.tvsubitemcount = (TextView) convertView.findViewById(R.id.tvsubitemcount);
            viewHolder.ivarrowlauncher = (ImageView)convertView.findViewById(R.id.arrowlauncher);

            viewHolder.checkboxselection=(CheckBox)convertView.findViewById(R.id.checkboxdeletion);
            checkBoxSelection=viewHolder.checkboxselection;
             viewHolder.checkboxselection.setChecked(checkBoxState[position]);
            viewHolder.ivarrowlauncher = (ImageView)convertView.findViewById(R.id.arrowlauncher);
             mainlayoutrl = (RelativeLayout)convertView.findViewById(R.id.clrrlmain);
             sublayoutll = (LinearLayout)convertView.findViewById(R.id.clrowll);
             arrowlayoutll = (LinearLayout)convertView.findViewById(R.id.clarrowll);    
             final Context context = ContentListActivity.contentListActivity;
             if(viewHolder.checkboxselection.isChecked()) {
                                  mainlayoutrl.setBackgroundColor(ctxt.getResources().getColor(R.color.checkboxrowselect));
                  sublayoutll.setBackgroundColor(ctxt.getResources().getColor(R.color.checkboxrowselect));
                  arrowlayoutll.setBackgroundColor(ctxt.getResources().getColor(R.color.checkboxrowselect));
             } else  {
                  mainlayoutrl.setBackgroundColor(ctxt.getResources().getColor(R.color.white));
                  sublayoutll.setBackgroundColor(ctxt.getResources().getColor(R.color.white));
                  arrowlayoutll.setBackgroundColor(ctxt.getResources().getColor(R.color.white));
             }

             sublayoutll.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
            if (Config.networkConnectionCheck(context)) {
        if(filteredContentList.get(position).type.equalsIgnoreCase("FOLDER")) {
        ContentListActivity.ListarrowClick(position+1,context);
                        } else if (refreshFlag == false) {
        ContentListActivity.oldviewContent(position+1,context);
                        } else

                    } else {
                        ContentListActivity.oldofflineViewContent(position+1,context);
                    }
                }
             });

             arrowlayoutll.setOnClickListener(new OnClickListener() 
             {
                    @Override
                    public void onClick(View v) {
                    ContentListActivity.ListarrowClick(position+1,context);
                }
                 });
             viewHolder.ivfilesDownload=(ImageView)convertView.findViewById(R.id.document_list_row_download_imageview);

             //newly added by venkat 
             viewHolder.ivfilesdownloaded=(ImageView)convertView.findViewById(R.id.document_list_row_downloaded_imageview);

             viewHolder.tvDocumentDescription=(TextView)convertView.findViewById(R.id.tvdocumentdescription);
        } else {
            viewHolder = (DocumentListViewHolder) convertView.getTag();
        }
        viewHolder.tvDocumentTitle.setText(filteredContentList.get(position).name);
            String desc = filteredContentList.get(position).versiondescription;
        if (desc != null) {
            viewHolder.tvDocumentDescription.setText(filteredContentList
                    .get(position).versiondescription);
        }
        String doctype = filteredContentList.get(position).type;
        String subitemcount = filteredContentList.get(position).subitemcount;
        if (doctype.equalsIgnoreCase(ctxt.getResources()
                .getString(R.string.pdf))) {
            viewHolder.ivDocumentdoctypeIcon
                    .setImageResource(R.drawable.pdfbigicon);
        } else if (doctype.equalsIgnoreCase(ctxt.getResources().getString(
                R.string.swf))) {
            viewHolder.ivDocumentdoctypeIcon
                    .setImageResource(R.drawable.flashbigicon);
        } if(doctype.equalsIgnoreCase(ctxt.getResources().getString(
                R.string.folder)))
        {
            viewHolder.ivarrowlauncher.setVisibility(View.INVISIBLE);
        }
        if (filteredContentList.get(position).isupdateavailable
                .equalsIgnoreCase(ctxt.getResources().getString(
                        R.string.update_false_status))) {
        } else if (filteredContentList.get(position).isupdateavailable
                .equalsIgnoreCase(ctxt.getResources().getString(
                        R.string.update_true_status))) {
                    WebAPI webapi = new WebAPI(ctxt);
                            if (LoginHandler.arraylistdata.size() == 1) {
                                user_id = LoginHandler.arraylistdata.get(0)
                                        .getUserid();
                                org_id = LoginHandler.arraylistdata.get(0)
                                        .getOrgId();
                            } else {
                                user_id = LoginHandler.arraylistdata.get(
                                        OrgListActivity.selected_org_pos)
                                        .getUserid();
                                org_id = LoginHandler.arraylistdata.get(
                                        OrgListActivity.selected_org_pos)
                                        .getOrgId();
                            }
                            LoginDatabaseHandler loginDBHandler = new LoginDatabaseHandler(
                                    ctxt);
                            loginDBHandler.open();
                            int toglState = loginDBHandler.checkOffToggleState(
                                    user_id, org_id, filteredContentList
                                            .get(position).dockey.toString());              
                                }
                            } else
                                versionUpdate(position, ctxt);
                        }
                    });
        }
        /*ends*/        
        return convertView;
    }

0 个答案:

没有答案