删除所有ListView行

时间:2013-01-26 03:28:33

标签: android android-listview

我已成功将pulltorefresh listview集成到我的实际代码中。

但是,当列表更新时,它会将所有存在的行添加到列表的末尾。我想在更新之前清除所有列表元素,但我坚持

如何删除listview中的这些行。行项目是可缓存的元素我认为像清除缓存可以工作吗?请任何想法。我想摆脱listview行。

<com.dmobile.pulltorefresh.PullRefreshContainerView
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="2dp"
    android:scrollingCache="false"
    android:listSelector="@drawable/list_selector"
    />

这是我的高效适配器

            EfficientAdapter efficienadapter=new EfficientAdapter(Actualites.this,result);
            //EfficientAdapter.isActusAstuce=true;
            mList.setAdapter(efficienadapter);

这是我的oncreate方法

mRefreshHeader = new TextView(this);

        mImage= new ImageView(this);

        mRefreshHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);

        mRefreshHeader.setTypeface(null, Typeface.BOLD);

        mRefreshHeader.setTextColor(getResources().getColor(R.color.blue));

        mRefreshHeader.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,

LayoutParams.MATCH_PARENT));

        mRefreshHeader.setGravity(Gravity.CENTER);

        mRefreshHeader.setText("Pull to refresh...");


        mImage.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

      //  LinearLayout.LayoutParams params=new LinearLayout.LayoutParams
           //     ((int)LayoutParams.WRAP_CONTENT,(int)LayoutParams.WRAP_CONTENT);

       // params.leftMargin=50;

       // mImage.setLayoutParams(params);

        int id = getResources().getIdentifier("boutton_retour", "drawable", getPackageName());

        //mImage.setImageResource(id);   

        mContainerView = (PullRefreshContainerView) findViewById(R.id.container);

        mContainerView.setRefreshHeader(mRefreshHeader);

        mContainerView.setRefreshHeader(mImage);

        mContainerView.setOnChangeStateListener(new OnChangeStateListener() {

            @Override

            public void onChangeState(PullRefreshContainerView container, int 

州){                     开关(州){

                case PullRefreshContainerView.STATE_IDLE:

                case PullRefreshContainerView.STATE_PULL:

                    mRefreshHeader.setText("Tirez pour actualiser...");

                    break;

                case PullRefreshContainerView.STATE_RELEASE:

                    mRefreshHeader.setText("Relâchez pour rafraîchir...");

                    break;

                case PullRefreshContainerView.STATE_LOADING:

                    mRefreshHeader.setText("Chargement en cours...");

                    new Thread(new Runnable() {

                        @Override

                        public void run() {
                            Actualites.this.runOnUiThread(new Runnable() {

                                @Override

                                public void run() {

                                    try {

                                        Thread.sleep(2000);

                                    } catch 

(InterruptedException e){

        e.printStackTrace();
                                    }
                                    //refresh ui

                                    new loadingTask().execute("");


                                    mContainerView.completeRefresh();
                                }
                            });

                        }


                    }).start();

                    break;

                }

            }

        });


        mList = mContainerView.getList();

        mList.setCacheColorHint(Color.TRANSPARENT);

        // PostList for ListView

        /// START AsyncTask here

        new loadingTask().execute("");


  note       new loadingTask().execute("") is an async background task

1 个答案:

答案 0 :(得分:0)

首先,清除结果数组/ arrayList或列表,... 之后,通知适配器同步列表项

result.clear();
efficienadapter.notifyDataSetChanged();

希望这个帮助