#StackBounty: #java #android #android-listview #in-app-billing #onskudetailsresponce Google InApp Billing – Binding title of skuDetails…

Bounty: 50

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 entire code used for establishing connection, getting the SKU Details , binding it array list and setting the adapter to the ListView Control in "OnCreateView"

Code for Establishing connection

private void startBillingServiceConnection(){
        //Initialize a billing client
        billingClient = BillingClient.newBuilder(this.getActivity())
        //Establish a connection to Google Play
        billingClient.startConnection(new BillingClientStateListener() {
            public void onBillingSetupFinished(BillingResult billingResult) {
                if (billingResult.getResponseCode() ==  BillingClient.BillingResponseCode.OK) {

                    // The BillingClient is ready. You can query purchases here....
            public void onBillingServiceDisconnected() {
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.

Code for querySkDetails

public void querySkuDetails() {
        Log.i(TAG, "querySkuDetails");

        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
                new SkuDetailsResponseListener() {
                    public void onSkuDetailsResponse(BillingResult billingResult,
                                                     List<SkuDetails> skuDetailsList) {
                        if (billingResult == null) {
                        int responseCode = billingResult.getResponseCode();
                        String debugMessage = billingResult.getDebugMessage();
                        switch (responseCode) {
                            case BillingClient.BillingResponseCode.OK:
                                if (skuDetailsList != null && skuDetailsList.size() > 0) {
                                    for (SkuDetails p : skuDetailsList) {
                                        subscribeItemDisplay.add("Product Name - "+p.getOriginalPrice()+": "+p.getSubscriptionPeriod()+": "+p.getFreeTrialPeriod());

Code in "OnCreateView"

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mainHandler = new Handler();

        // Inflate layout
        View view = inflater.inflate(R.layout.subscribe_fragment, container, false);            
        subscriptionsListView = view.findViewById(R.id.subscriptionsView);            
        return view;

Code for loadInAppProductIDS

public void loadInAppProductIDS() {

        new Thread(new Runnable() {
            public void run() {
                LIST_OF_SKUS= Collections.unmodifiableList(myProductIDs);
                mainHandler.post(new Runnable() {
                    public void run() {
                        arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.subscription_items_list, subscribeItemDisplay);

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

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.