尝试使用PullToRefreshScrollView更新scrollldown上的listview

时间:2014-07-24 08:25:22

标签: android listview scrollview

我正在尝试使用PullToRefreshScrollView更新列表视图。我能够更新arraylist而不是listview。我检查了arraylist的大小,它每增加一个清爽。但listview显示的内容与之前相同。这是我的代码:

   <com.handmark.pulltorefresh.library.PullToRefreshScrollView
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:id="@+id/pull_refresh_scrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    ptr:ptrAnimationStyle="flip"
    ptr:ptrMode="both" >

  <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"            
        android:layout_below="@+id/relativeLayout2"
        android:layout_above="@+id/reltive"
        android:divider="#b5b5b5"
        android:dividerHeight="0.5dp"
        android:layout_marginBottom="62dp"
        android:listSelector="@drawable/list_selector"
        android:fadingEdge="none">
</ListView>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>

异步更新列表视图:

private class GetOnPullTask extends AsyncTask<Void, Void, String[]> {
    ArrayList<DealOffer> refreshedArray = new ArrayList<DealOffer>();
    @Override
    protected String[] doInBackground(Void... params) {
        // Simulates a background job.
        try {
            Thread.sleep(4000);
            DealGaliJSONReader dealGaliReader = new DealGaliJSONReader();
            refreshedArray = dealGaliReader
                    .getJSONParserDealList(
                            DealGaliConstants.lat,
                            DealGaliConstants.lon,
                            DealGaliConstants.authId);

        } catch (InterruptedException e) {
        }
        return null;
    }

    @Override
    protected void onPostExecute(String[] result) {
        // Call onRefreshComplete when the list has been refreshed.
        mPullRefreshScrollView.onRefreshComplete();
        TabWidget.setVisibility(View.VISIBLE);
        if(refreshedArray.size()>0){
            for(int i=0; i<refreshedArray.size();i++){                      
                DealGaliConstants.dealList.add(refreshedArray.get(i));
            }
            adapter.notifyDataSetChanged();
            offerLists.invalidateViews();
        }
        Log.i("array size", DealGaliConstants.dealList.size()+"");

        super.onPostExecute(result);
    }
}

1 个答案:

答案 0 :(得分:0)

我是以错误的方式做的。我应该在listview中使用PullToRefreshListView进行刷新。这是我做的:

  <com.handmark.pulltorefresh.library.PullToRefreshListView
    android:id="@+id/pull_refresh_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:cacheColorHint="#00000000"
    android:divider="#19000000"
    android:dividerHeight="4dp"
    android:fadingEdge="none"
    android:fastScrollEnabled="false"
    android:footerDividersEnabled="false"
    android:headerDividersEnabled="false"
    android:smoothScrollbar="true" />

MyAsync和以前一样......