【发布时间】:2016-01-08 15:23:03
【问题描述】:
我正在训练解析新闻网站。我在解析图像时遇到了一些问题。
http://www.ua-football.com/ - class="stripe-container
来自MainActivity.class的代码
@Override
protected Void doInBackground(Void... params){
arraylist = new ArrayList<HashMap<String, String>>();
try{
Document doc = Jsoup.connect(url).userAgent("\"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10").get();
for (Element container : doc.select("div[class=stripe-container]")){
for (Element ul_li : container.select("ul li")){
HashMap<String, String> map = new HashMap<String, String>();
Elements img_src = ul_li.select("img[src]");
String img = img_src.attr("src");
System.out.println(img);
//map.put("logo", img);
map.put("text", ul_li.text());
map.put("logo",img);
arraylist.add(map);
}
}
} catch (IOException e){
e.printStackTrace();
}
return null;
}
和getView 来自Adapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView text_of_news;
ImageView logo;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.list_item, parent, false);
// Get the position
resultp = data.get(position);
text_of_news = (TextView) itemView.findViewById(R.id.text_of_news);
logo = (ImageView) itemView.findViewById(R.id.imageView);
text_of_news.setText(resultp.get(MainActivity.TEXT_OF_NEWS));
imageLoader.DisplayImage(resultp.get(MainActivity.LOGO), logo);
return itemView;
}
打开应用程序后,我可以看到文本,但我从ImageLoader 找到默认的image 而不是必需的图像
我的失败在哪里?
【问题讨论】:
-
您是否正在使用
notifyDataSetChanged()更新适配器? -
@MatousHybl 我应该在声明适配器(onPostExecute)的方法中这样做吗?
标签: android image html-parsing jsoup