我是 android 应用程序服务的新手,对我来说似乎有点复杂,我已经完成了所有初始程序来实现它,但我停留在购买状态(我认为是这样)。我有一个 ListView ,在 onitem 点击监听器中我已经这样做了:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
purchaseposition= position;
if(list.get(position).getPurchase().contentEquals("Buy")){
val = billingService.requestPurchase("android.test.purchased", payloadContents);
}else{
SharedPreferences.Editor editor = preference.edit();
editor.putInt("URLPOSITION", position);
editor.commit();
Intent quiz=new Intent("com.powergroupbd.appbil.QUIZACTIVITY");
startActivity(quiz);
}
}
这意味着如果 ListView 包含文本“购买”,那么我将向市场发送请求以使用测试购买 ID 进行购买。现在我希望如果购买成功,那么我会将 ListView 的文本从“购买”到“播放”并启用要播放的测验。但这是我认为我错过了一切的部分。在购买状态更改中,我编写了这段代码来执行此操作:
@Override
public void onPurchaseStateChange(PurchaseState purchaseState,
String itemId, int quantity, long purchaseTime,
String developerPayload) {
if (Consts.DEBUG) {
Log.i("Tag", "onPurchaseStateChange() itemId: " + itemId + " "
+ purchaseState);
}
if (purchaseState == PurchaseState.PURCHASED) {
ownedItems.add(itemId);
list.get(purchaseposition).setPurchase("Play");
}
// YOU can also add other checks here
}
但它永远不会改变 ListView 的文本,我永远无法玩测验,请问我需要一个完整的想法我该怎么做,我的错误在哪里?谢谢
最佳答案
您如何显示您的数据?
如果您使用的是 ListView 和数组适配器,则需要调用 adapter.notifyDataSetChanged();
这会告诉适配器您已更新信息,它可以刷新列表。如果您不使用数组适配器,您可以调用 findViewById(int)
并动态更改 View 。
关于java - 如何在 Android 中正确使用应用内计费服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11109740/