gpt4 book ai didi

java - OnActivityResult()

转载 作者:行者123 更新时间:2023-11-30 03:47:14 26 4
gpt4 key购买 nike

我有代码可以让我从计算器中获取值并进一步使用它:

//-----------------This section creates the keypad functionality
for (int o = 0; o < keybuttons.length; o++) {
final int n = o;
keybuttons[o] = (Button) findViewById(data.keyIds[n]);
keybuttons[o].setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
try {
String tmp = texts[selectEdit].getText()
.toString();
switch (n) {
case 3:
texts[selectEdit].setText(tmp.substring(0, tmp.length() - 1));
break; //get cursor position and delete char
case 7:
{
// Create intent for RealCalc.
Intent intent2 = new Intent("uk.co.quarticsoftware.REALCALC");
double x = 0; // Set initial value (double).
if (!texts[selectEdit].getText()
.toString()
.equals("")) {
x = Double.valueOf(texts[selectEdit].getText()
.toString());
}
intent2.putExtra("X", x);
// Launch calculator
try {
startActivityForResult(intent2, 0);
} catch (ActivityNotFoundException e) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=uk.co.nickfines.RealCalc"));
try {
startActivity(intent);
} catch (ActivityNotFoundException f) {
// Google Play Store app not available.
}
}
break;
} //open Calculator
case 11:
{
if (!tmp.contains("E")) texts[selectEdit].setText(tmp + "" + keybuttons[n].getText());
break;
} //check for E if dont have do default case
case 15:
{
TL.setVisibility(View.GONE);
break;
} //simulate back button
default:
{
texts[selectEdit].setText(tmp + "" + keybuttons[n].getText());
//get cursor start and end and get entire String
// replace selected String with button text
//insert back
break;
}
} //end of switch
} //end of try
catch (ActivityNotFoundException e) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=uk.co.nickfines.RealCalc"));
// Calculator not installed
} //calculator.num=n;
catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
EasyPhysActivity.error = sw.toString();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
// User pressed OK.
double value = data.getDoubleExtra("X", Double.NaN);
if (Double.isNaN(value)) {
// Calculation result was "Error".
} else {
// Calculation result ok.
}
} else {
// User pressed cancel or back button.
}
}
});

}
//----------------------------------------

但它不喜欢这三行:

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

如果我删除 @Override 它会变得更好,但它仍然显示错误

super.onActivityResult(requestCode, resultCode, data);

这里出了什么问题?

最佳答案

您不能在 OnClickListener 中覆盖 onActivityResult,因为它不存在于基类中。移动您的 onActivityResult 代码,使其位于您的 Activity 类中,而不是 OnClickListner

关于java - OnActivityResult(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14783758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com