我遇到了一个问题,这是我在近三年的 Android 开发过程中从未遇到过的问题......
我想拍照,拍照后EditText
活动的内容变得清晰。我正在做的是设置的值EditText
to Strings
using getText().toString()
拍照后恢复它们。
字符串与数据完美存储,但是当我使用setText
,它不起作用......奇怪的是,setHint
works!
怎么会这样?
这是我正在使用的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
grabImage(imgView);
for (int u = 0; u <= 2; u++)
{
if (savedImgs[u].equals(""))
{
imgs = u + 1;
savedImgs[u] = photo.toString();
break;
}
}
/*Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ---> It is a small bitmap, for icons...
imgView.setImageBitmap(thumbnail);
imgView.setVisibility(View.VISIBLE);*/
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
Toast.makeText(this, "Image couldn't be taken. Try again later.", Toast.LENGTH_LONG).show();
}
}
if (!tempSpotName.equals("") || !tempSpotDesc.equals("")) {
name.setText(tempSpotName);
description.setText(tempSpotDesc);
}
}
name
and description
是全球性的EditTexts
and tempSpotName
and tempSpotDesc
是全球性的Strings
.
如何设置文字?
onActivityResult()
不是返回 Activity 时调用的最后一个方法。你可以刷新你的记忆生命周期在文档中。 :)
正如我们在评论中讨论的,如果您致电setText()
再次使用类似的方法onResume()
这将覆盖中设置的任何文本onActivityResult()
.
Fragments 也是如此,您需要在 onViewStateRestored() 方法中进行更新(该方法是在 API 17 中添加的)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)