Android 如何使用JSoup获取页面中的所有图像,然后使用毕加索下载到ImageView?
我正在尝试解析网页的图像,并使用毕加索在网格中显示它们。我的网格可以很好地处理虚拟数据和毕加索提供的样本。我的代码不会在我的网格中产生任何东西,甚至不会产生错误消息 我想解析这个特定网页的图像链接,这样我就不必像毕加索那样手动将它们添加到我的项目中。这是我的密码:Android 如何使用JSoup获取页面中的所有图像,然后使用毕加索下载到ImageView?,android,jsoup,picasso,Android,Jsoup,Picasso,我正在尝试解析网页的图像,并使用毕加索在网格中显示它们。我的网格可以很好地处理虚拟数据和毕加索提供的样本。我的代码不会在我的网格中产生任何东西,甚至不会产生错误消息 我想解析这个特定网页的图像链接,这样我就不必像毕加索那样手动将它们添加到我的项目中。这是我的密码: public GridViewAdapter(Context context) { this.mContext = context; Thread downloadThread = new Thread() {
public GridViewAdapter(Context context) {
this.mContext = context;
Thread downloadThread = new Thread() {
public void run() {
try {
Document doc = Jsoup.connect("http://sample.com/examples.html").get();
Elements imgs = doc.select("img");
//String img_url = imgs.attr("src");
for (Element i : imgs) {
//added this line to check if my jsoup is correct
System.out.println(i.attr("abs:src"));
urls.add(i.attr("abs:src"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
downloadThread.start();
}
这是我的适配器的getView
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
RecordHolder holder = null;
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.row_grid_view, parent, false);
holder = new RecordHolder();
holder.title = (TextView) view.findViewById(R.id.fruitName);
holder.thumbnail = (ImageViewTopCrop) view.findViewById(R.id.fruitImage);
holder.thumbnail.setScaleType(ImageViewTopCrop.ScaleType.MATRIX);
view.setTag(holder);
} else {
holder = (RecordHolder) view.getTag();
}
// Set Text
holder.title.setText(position);
//set thumbnail URL
String url = getItem(position);
// Trigger the download of the URL asynchronously into the image view.
Picasso.with(mContext) //
.load(url) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.tag(view) //
.into(holder.thumbnail);
return view;
现在,我的logcat显示我的Jsoup是正确的,它打印正确的链接。但是,我的GridView仍然没有显示任何内容。如果没有显示下载图像,您是否能够在girdview中看到错误图像,因为您已经设置了错误图像,通常,在毕加索中,在显示错误占位符之前,请求将重试三次。很好的调用。事实上,什么也看不出来。忘了提及:您在AndroidManifest.xml中提到internet权限了吗?还要检查占位符图像是否显示?我有互联网权限。我的网格使用我提供的示例数据—在mContext=context之后添加的URL列表。占位符未显示。确定尝试检查url、上下文、视图的值是否不为null,即,设置if条件以确保这些变量不为null,如果不为null,则调用毕加索代码,否则打印日志消息