我正在尝试解析网页的图片并使用Picasso在网格中显示它们。我的网格与伪数据和毕加索提供的样本一起工作正常。我的代码在我的网格中没有产生任何东西(甚至不是错误信息)。
我想解析这个特定网页的图像链接,这样我就不必手动将它们添加到我的项目中(就像Picasso为例子所做的那样)。这是我的代码:
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仍然没有显示任何内容。