Search in sources :

Example 1 with ViewHolderCreator

use of in.srain.cube.views.list.ViewHolderCreator in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class WithGridView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_grid_view);
    mImageLoader = ImageLoaderFactory.create(getContext());
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_gridview, null);
    final GridView gridListView = (GridView) contentView.findViewById(R.id.rotate_header_grid_view);
    gridListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= 0) {
                final String url = mAdapter.getItem(position).optString("pic");
                if (!TextUtils.isEmpty(url)) {
                    getContext().pushFragmentToBackStack(MaterialStyleFragment.class, url);
                }
            }
        }
    });
    mAdapter = new ListViewDataAdapter<JsonData>(new ViewHolderCreator<JsonData>() {

        @Override
        public ViewHolderBase<JsonData> createViewHolder(int position) {
            return new ViewHolder();
        }
    });
    gridListView.setAdapter(mAdapter);
    mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.rotate_header_grid_view_frame);
    mPtrFrame.setLastUpdateTimeRelateObject(this);
    mPtrFrame.setPtrHandler(new PtrHandler() {

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            updateData();
        }

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
        }
    });
    // the following are default settings
    mPtrFrame.setResistance(1.7f);
    mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
    mPtrFrame.setDurationToClose(200);
    mPtrFrame.setDurationToCloseHeader(1000);
    // default is false
    mPtrFrame.setPullToRefresh(false);
    // default is true
    mPtrFrame.setKeepHeaderWhenRefresh(true);
    mPtrFrame.postDelayed(new Runnable() {

        @Override
        public void run() {
        // mPtrFrame.autoRefresh();
        }
    }, 100);
    // updateData();
    setupViews(mPtrFrame);
    return contentView;
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) GridView(android.widget.GridView) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) AdapterView(android.widget.AdapterView) JsonData(in.srain.cube.request.JsonData) MaterialStyleFragment(in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) ViewHolderCreator(in.srain.cube.views.list.ViewHolderCreator)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 CubeImageView (in.srain.cube.image.CubeImageView)1 JsonData (in.srain.cube.request.JsonData)1 ViewHolderCreator (in.srain.cube.views.list.ViewHolderCreator)1 PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)1 PtrHandler (in.srain.cube.views.ptr.PtrHandler)1 MaterialStyleFragment (in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment)1