Thursday 22 July 2021

Google InApp Billing - Binding title of skuDetailsList obtained from onSkuDetailsResponse to List View Control

I am new to the implementation of Google's Billing library and using this system to make subscriptions inside my app. I am trying to get the title of skuDetailsList which is obtained from onSkuDetailsResponse and adding to the ArrayList dataSource. I am setting the ArraryList as datasource to the adapter . The issue is the ListView is getting displayed empty every time even though there are items available in the ArrayList DataSource.

I tried adding dummy values to the datasource and found that they are getting displayed in the list view control. So, i have I debugged the code and found that the view is getting returned first and then the items are getting added to the ArrayList Datasource as onSkuDetailsResponse is getting called asynchronously.

Following is the code used for setting the adapter to the ListView Control in "OnCreateView"

View view = inflater.inflate(R.layout.subscribe_fragment, container, false);
---- Code here for establishing the connection to Google Play and querying skuDetails in the onBillingSetupFinished method ----
subscriptionsListView = view.findViewById(R.id.subscriptionsView);
arrayAdapter = new ArrayAdapter<String>(this.getActivity(), 
               R.layout.subscribtion_item_list, subscribeItemDisplay);
subscriptionsListView.setAdapter(arrayAdapter);
return view;

Following is the code being used for getting the skuDetails list and adding the title to the ArraList datasource

public void onSkuDetailsResponse(BillingResult billingResult,
                                                     List<SkuDetails> skuDetailsList) {
                        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                            if (skuDetailsList != null && skuDetailsList.size() > 0) {
                                subscribeItemDisplay.clear();
                                for(SkuDetails p:skuDetailsList){
                                    subscribeItemDisplay.add(p.getTitle());
                                }
                            }
                        }
                    }

Can you please suggest on how to add items to datasource, bind to the list view and then return the view?



from Google InApp Billing - Binding title of skuDetailsList obtained from onSkuDetailsResponse to List View Control

No comments:

Post a Comment