Reputation: 2734
I am totally new in appbiling service in android, and it seems to be a little bit complicated for me, I have done all the initial procedures to implement it , but I am stuck in the purchase state(I think so).I have a list view and in the onitem click listener I have done this:
@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);
}
}
that means if the list view contains a text 'Buy' then I am sending request to the market to buy with the test purchase id.Now I want that if purchase is successfull then I will change the text of the list view from 'Buy' to 'Play' and enable the quiz to be played. But here is the part where I think I missed everthing. In the purchase state change I wrote this code to do this:
@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
}
but it never change the text of the listview and I can never play the quiz, Please I need a complete Idea how can I do this and where is my mistake? thanks
Upvotes: 2
Views: 421
Reputation: 4762
How are you displaying your data?
if you are using a listview and an array adapter, you need to call adapter.notifyDataSetChanged();
This tells the adapter you have updated information and it can refresh the list. If your not using an array adapter, you could call findViewById(int)
and dynamically change the view.
Upvotes: 1