我正在嘗試在應用結算中執行一些操作以刪除廣告。使EditText在活動開始時工作
我有這段代碼:
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
// Have we been disposed of in the meantime? If so, quit.
if (mAbHelper == null)
return;
// Is it a failure?
if (result.isFailure()) {
return;
}
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = premiumPurchase != null;
updateInterface();
}
};
/**
* Updates interface
*/
private void updateInterface() {
Button saveButton = (Button) findViewById(R.id.btUpgrade);
Button btUpgrade = (Button) findViewById(R.id.btUpgrade);
if (mIsPremium) {
final EditText edittext = (EditText) findViewById(R.id.editTextAntiAdsKey);
saveButton = (Button) findViewById(R.id.buttonSaveAntiAdsKey);
if (edittext != null && edittext.getText() != null) {
Constants.ANTI_ADS_VALUE = edittext.getText().toString().trim();
} else {
Constants.ANTI_ADS_VALUE = "ERROR";
}
if ("".equals(Constants.ANTI_ADS_VALUE)
|| Constants.ANTI_ADS_VALUE.equals(this
.getString(R.string.app_name))) {
Constants.ANTI_ADS_VALUE = "";
Toast.makeText(MainActivity.this,
getResources().getString(R.string.app_name),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(
MainActivity.this,
getResources().getString(R.string.app_name) + " ("
+ edittext.getText() + ")", Toast.LENGTH_LONG)
.show();
}
SharedPreferences settings = getSharedPreferences(
Constants.PREFERENCES_FILE, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(Constants.ANTI_ADS_KEY, Constants.ANTI_ADS_VALUE);
editor.commit();
editor.clear();
} else {
btUpgrade.setEnabled(true);
}
}
的事情是我必須按下一個按鈕,使這個代碼工作。 我希望這段代碼能在一個活動開始時工作。
我是新手,所以我想知道是否有可能?
謝謝
更具體 –
不,它是不可能的。在'onCreate'中,僅創建視圖,那麼您輸入的值將不可用。 –
當我點擊一個按鈕來做兩件不同的事情時,有可能嗎? – user3627763