【发布时间】:2016-01-09 03:19:18
【问题描述】:
好的,我要做的是将第一个方法(SaveTemplate)中的变量“int putPrice”插入到第二种方法(SaveTemplateTask)中的变量“price”中。
第一个公共方法:
public boolean SaveTemplate(View view) {
final EditText txtPrice = new EditText(getContext());
txtPrice.setKeyListener(DigitsKeyListener.getInstance(false, false));
new AlertDialog.Builder(getContext())
.setTitle(selectedProduct.getName())
.setMessage("You will earn every dollar above the base price (" + "USD $" + selectedProduct.getCost() + ") for this item!")
.setView(txtPrice)
.setPositiveButton("Sell Product", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// putPrice is the variable set by the user. I want to pass this into SaveTemplateTask.
int putPrice = Integer.parseInt(txtPrice.getText().toString());
Toast.makeText(getActivity().getApplicationContext(), "Saving design", Toast.LENGTH_SHORT).show();
new SaveTemplateTask().execute();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
return true;
}
第二种私有方法:
private class SaveTemplateTask extends AsyncTask<Void, Integer, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
try {
MainActivity mainActivity = ((MainActivity) getActivity());
mainActivity.DrawDesignOnResult();
UUID uuid = mainActivity.SaveResultBitmapToExternalStorage();
// price is the variable I ultimately want to be determined by putPrice, because this is the variable that is ultimately uploaded to the back-end.
int price = Integer.parseInt(putPrice);
String productType = selectedProduct.getSKU();
mainActivity.UploadExternalFileToServer(uuid.toString());
ParseHelper.UploadDesignToMarketFeed(GenerateBitmapFromTemplateView(), uuid, price, productType);
} catch (IOException e) {
Log.e(TAG, e.toString());
return false;
} catch (ParseException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
return false;
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if(!result) { Toast.makeText(getActivity().getApplicationContext(), R.string.failed_to_save_image, Toast.LENGTH_SHORT).show(); }
Toast.makeText(getActivity().getApplicationContext(), "Design saved", Toast.LENGTH_LONG).show();
}
}
我基本上只是对如何在不同类之间传递变量感到困惑,以便我最终可以将价格设置为用户最初在第一个公共类中输入的函数。
【问题讨论】:
标签: java android asynchronous parse-platform