无限/无限滚动不适用于gridview?

时间:2015-07-26 14:35:32

标签: android gridview gson retrofit infinite-scroll

我的应用尝试使用Retrofit和Gson从api调用中获取各种信息。此信息需要显示为gridview,gridview需要在滚动时重新填充。截至目前,我可以获得前10项,就是这样。如何为此添加无限滚动功能。

公共类ProductListing扩展了Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.product_listing_act);
    init();
}

public void productListingApiCall() {

    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(base_url).setLogLevel(RestAdapter.LogLevel.FULL).build();
    final ProductListingApi productListingApi =
            restAdapter.create(ProductListingApi.class);
    productListingApi.getFeed(file, operation_condition, search_string_condition, minprice_condition, maxprice_condition, mincusratings_condition,
            maxcusratings_condition, discount_condition, catids_condition, brands_condition, affids_condition, start_row_condition, limit_condition,
            orderby_condition, sortby_condition, new Callback<ProductListingPojo>() {

                @Override
                public void success(ProductListingPojo productListingPojo, Response response) {
                    final ProductListingPojo product = productListingPojo;
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            product_key = Arrays.copyOf(product.getProductkey(),
                                    product.getProductkey().length);
                            cs_category_id = Arrays.copyOf(product.getCsCategoryid(),
                                    product.getCsCategoryid().length);
                            title = Arrays.copyOf(product.getTitle(),
                                    product.getTitle().length);
                            price = Arrays.copyOf(product.getSellingprice(),
                                    product.getSellingprice().length);
                            mrp = Arrays.copyOf(product.getMrp(),
                                    product.getMrp().length);
                            discount = Arrays.copyOf(product.getDiscountpercent(),
                                    product.getDiscountpercent().length);
                            image = Arrays.copyOf(product.getProductimageSmall1(),
                                    product.getProductimageSmall1().length);
                            cus_agg_num = Arrays.copyOf(product.getCustratingAggNum(),
                                    product.getCustratingAggNum().length);

                        }
                    }).run();

                    setAdapter();
                }

                @Override
                public void failure(RetrofitError error) {
                    tv_title_header.setText(error.getMessage());
                    Log.e("error", error.getMessage());
                }
            });
}

void setAdapter() {
    adapter = new ProductListingGridAdapter(this, title, image, price, mrp, discount);
    gv_product_listing_act.setAdapter(adapter);
}

}

OnCreate()中的init()将初始化所有视图并首次调用productListingApiCall()。 api工作的方式是,我将请求前10个项目(start_row_condition:0和limit:10),然后在滚动后到达底部它应该添加下一个10,因此我需要调用api(start_row_condition) :10和限制:10)。我该如何实现呢。

0 个答案:

没有答案