我已成功地将 pulltorefresh 列表视图集成到我的实际代码中。
但是,当列表更新时,它会将所有存在的行添加到列表的末尾。我想在进行更新之前清除所有列表元素,但我坚持
如何删除列表视图中的这些行。行项目是可缓存元素我认为清除缓存之类的东西可以工作吗?请有任何想法。我想摆脱 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
(中断异常 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