【发布时间】:2012-11-03 10:48:50
【问题描述】:
我遇到了一个使用 Android 开发近三年来从未遇到过的问题...
我想拍照,拍照后,活动的EditTexts就清晰了。我正在做的是将EditText 的值设置为Strings,使用getText().toString() 在拍照后恢复它们。
字符串与数据完美存储,但是当我使用setText时,它不起作用......奇怪的是setHint起作用了!
怎么可能?
这是我正在使用的代码:
@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 和 description 是全局的 EditTexts 和 tempSpotName 和 tempSpotDesc 是全局的 Strings。
如何设置文字?
【问题讨论】:
-
我们可以看看你的布局xml代码吗?你甚至到达 name.setText(tempSpotName); ?你调试过这个吗?
-
只是检查,但 setText 被调用但显示不正确? if 语句不会阻止它被调用吗? (只是仔细检查,因为 setText 应该可以工作)
-
你在其他地方打电话给
setText()吗?可能在onResume()? -
@Goot 和 @AJak 是的,我重新定义了 if 语句,它正在被调用。否则
setHint将不起作用...@Sam 我想我在 onCreate() 中调用它...我要检查它... -
@Sam okey...我没有意识到我在 onCreate() 中调用了 setText...我是天才,哈哈,非常感谢!如果你回答我会检查它作为接受的答案!
标签: android android-edittext settext