我试图从存储在表中的 url 获取图像,但是当我尝试获取图像时,ImageView 不包含任何内容,它只是空白。在我下面的代码中,我使用 Picasso 来获取图片:public class Imageoffam extends AppCompatActivity {private boolean success = false; // booleanprivate ConnectionClass connectionClass;public TextView tmtmt;public ImageView dede;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_imageoffam); getSupportActionBar().hide(); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); tmtmt = (TextView) findViewById(R.id.tomato) ; dede = (ImageView) findViewById(R.id.dededede); connectionClass = new ConnectionClass(); SyncData orderData = new SyncData(); orderData.execute("");}private class SyncData extends AsyncTask<String, String, String> { String msg = "Success"; ProgressDialog progress; @Override protected void onPreExecute() { progress = ProgressDialog.show(Imageoffam.this, "Synchronising", "Please Wait...", true); } @Override protected String doInBackground(String... strings) { try { Connection conn = connectionClass.CONN(); if (conn == null) { msg = "Please Check Your Connection"; success = false; } else { String dta = getIntent().getStringExtra("blala"); String query = "SELECT Images.Fimage,family.FName,family.FInfo,family.CID FROM Images INNER JOIN family ON family.FID = Images.FID WHERE family.FInfo = (N'" +dta+ "')"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query);尽管它没有在 ImageView 中显示图像,但它没有给出任何错误消息。有人可以告诉我我做错了什么吗?任何帮助,将不胜感激。
3 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
使用 Picasso 时,不需要 AsyncTask,只需执行以下操作:
Picasso.with(context).load(imageUri).into(ivBasicImage);
例如:
String imageUri = "https://i.imgur.com/tGbaZCY.jpg";
ImageView ivBasicImage = (ImageView) findViewById(R.id.ivBasicImage);
Picasso.with(context).load(imageUri).into(ivBasicImage);
您也可以尝试Glide:
Glide.with(context).load(url).into(imageView);
哔哔one
TA贡献1854条经验 获得超8个赞
如果将图像 uri 存储在 db 中,则需要通过 imageView.setImageUri(uri) 在 ImageView 上设置 uri;从 db 获取 uri 之后
添加回答
举报
0/150
提交
取消