gpt4 book ai didi

java - 根据真/假条件从 URL 绘制位图

转载 作者:行者123 更新时间:2023-12-01 12:48:04 24 4
gpt4 key购买 nike

使用以下代码,我只想在 chatMessageObj.left 为 true 时显示图像,但图像却显示不出来。

public View getView(int position, View convertView, ViewGroup parent) {

...

String personPhotoUrl = "Image url";
personPhotoUrl = personPhotoUrl.substring(0, personPhotoUrl.length() - 2) + PROFILE_PIC_SIZE;
if (chatMessageObj.left) {
new LoadProfileImage(chatImage).execute(personPhotoUrl);
}

...

}

private class LoadProfileImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public LoadProfileImage(ImageView bmImage) {
this.bmImage = bmImage;
}

protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}

我需要这样的东西:

protected void onPostExecute(Bitmap result, boolean display) {
bmImage.setImageBitmap(display ? result : null);
}

谢谢。

最佳答案

这是因为listview总是保持刷新,所以你需要做的就是添加else block ,

类似这样的事情,

if (chatMessageObj.left) {
new LoadProfileImage(chatImage).execute(personPhotoUrl);
} else {
chatImage.setVisibility(View.GONE);
}

希望这对您有帮助:)

关于java - 根据真/假条件从 URL 绘制位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24492397/

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