如何在适配器类中进行谷歌inapp购买

时间:2013-12-05 05:42:12

标签: android in-app-purchase

我正在开发一款应用谷歌购买应用的应用。现在有一个按钮购买,点击按钮后我必须调用inapp购买,但这是我面临的问题,立即购买按钮是在适配器类,因此我怎么能在适配器类中进行inapp购买 这是我的代码

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.loadmore_btn:
        // call a url with ofset & limit with Thread
        if (getbookItems.getContentName() == "LoadMore") {
            booksItemsInfo.remove(booksItemsInfo.size() - 1);
        }
        if (UIAndDataLoader.offset < bookcategoryItem.getCount()) {
            if (UIAndDataLoader.offset < DBTotalContentCount) {
                UIAndDataLoader.offset = UIAndDataLoader.offset + 10;
                UIAndDataLoader.loadFlag = 0;
                myActivity.Tostart();
            } else {
                myActivity.URLConfig = MagURLConfig.bURL
                        + MagURLConfig.uMAILIDNAME
                        + _Settings.getString("setEmail-ID", null)
                        + MagURLConfig.uPASSWORD
                        + _Settings.getString("setPassword", null)
                        + MagURLConfig.CATEGORYID
                        + bookcategoryItem.getCatId() + MagURLConfig.OFFSET
                        + DBTotalContentCount + MagURLConfig.LIMIT;
                UIAndDataLoader.bookcountlimit = 1;
                myActivity.toStartRefresh(true);
            }
        }
        break;

    case R.id.btn_buynow:
        // System.out.println("this is buy btn------------->");
        BookDataLoader.ActionButtonOnclick(btn_txt, action_btn,
                getbookItems, "");
        break;

    case R.id.preview:
        BookDataLoader.ActionButtonOnclick(btn_txt, action_btn,
                getbookItems, "Preview");
        break;
    }
}
}

1 个答案:

答案 0 :(得分:0)

您可以在同一个activity.thats中声明适配器类,以便您可以使用mHelper对象。 我在puchase项目中的一个应用程序中完成了相同的功能。

如: -

     holder.relative_layout_btn_buy.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub


                                try {

                                    if(isOnline())
                                                    mHelper.launchPurchaseFlow(OnlineStoreList.this,"android.test.purchased",RC_REQUEST,mPurchaseFinishedListener, "");

                                    else
                                    {
                                        NetworkAlert();
                                    }
                                    } catch (Exception e) {
       //                   Toast.makeText(getApplicationContext(),"Please wait...Try after some time!! " ,1).show();
                                    Log.e("Exception", "===>" + e.toString());
                                    complain(e.getMessage());
                                }


                        }
                    });

我希望能有所帮助。谢谢!!