我的 MainActivity.java 中有这样的东西
m_dbmanager.addRow(
"http://pl.wikipedia.org/wiki/1_stycznia",
"1",
"http://assets3.parliament.uk/iv/main-large//ImageVault/Images/id_7382/scope_0/ImageVaultHandler.aspx.jpg");
第一个引号是我在另一个 Activity 中发送到 webview 的链接,第二个引号(“1”)是行的名称,最后第三个引号是我想在一行中显示的图像的 url。
这是我负责与图像交互的代码部分。
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Order o = items.get(position);
if (o != null)
{
TextView name = (TextView) v.findViewById(R.id.row_textView);
ImageView image_view = (ImageView) v.findViewById(R.id.row_imageView);
if (name != null)
{
name.setText("Name: "+o.getOrderName());
}
if(image_view != null)
{
final String thumbail = o.getOrderImage(); //TODO, just trying
final String link = o.getOrderLink();
image_view.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent intent = new Intent(MainActivity.this, TemplateActivity.class);
intent.putExtra("urlString", link);
startActivity(intent);
}
});
}
}
return v;
}
}
Order class in case someone would like to see
现在 - 我该怎么做才能在对象“row_imageView”的位置显示 addRow 中指定的 URL 中的图像?
提前谢谢你,
最佳答案
您可以使用 Picasso library将图像从 URL 加载到 ImageView。
下载 jar 并将其添加到项目的 libs 文件夹中。然后使用下面的代码将图像从 url 或什至任何其他资源加载到 ImageView 中:
Picasso.with(your_context).load(url_of_image).placeholder(R.drawable.icon)
.noFade().into(your_imageView);
关于Android - 从数据库中获取图像 url 并在 ImageView 中显示该图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25765151/