android app에서 listview의 텍스트와 이미지를 구문 분석하고 있습니다. 내가 listview에서 텍스트를 성공적으로 구문 분석했지만 이미지를 구문 분석하지 못했습니다. 나는 또한 url/image.jpeg와 같은 이미지의 URL을 얻었지만 donot은 해당 URL에서 이미지 뷰로 이미지를 얻는 방법을 알고있다. 코드는 다음과 같습니다listview에서 이미지 구문 분석
NodeList nodes = doc.getElementsByTagName("item");
for (int i = 0; i < nodes.getLength(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
bitmap = DownloadImage(XMLfunctions.getValue(e, "thumb"));
image = (ImageView) findViewById(R.id.image);
image.setImageBitmap(bitmap);
Log.e("imageView","image is:"+image);
//map.put("id", XMLfunctions.getValue(e, "id"));
map.put("title", XMLfunctions.getValue(e, "title"));
map.put("author", XMLfunctions.getValue(e, "author"));
map.put("catagory",XMLfunctions.getValue(e, "catagory"));
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.mainview,
new String[] {"title","author", "catagory" },
new int[] {R.id.title, R.id.author,R.id.catagory });
setListAdapter(adapter);
메소드 DownloadImage입니다 : 내가 구글에서 검색하고 다른 방법을 시도했지만 이미지를 분석 할 수있다
private Bitmap DownloadImage(String URL)
{
Log.v("url",URL);
Bitmap bitmap = null;
InputStream in = null;
try {
in = openHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
Log.e("image","image"+bitmap);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
private InputStream openHttpConnection(String urlStr) {
InputStream in = null;
int resCode = -1;
try {
URL url = new URL(urlStr);
URLConnection urlConn = url.openConnection();
if (!(urlConn instanceof HttpURLConnection)) {
throw new IOException ("URL is not an Http URL");
}
HttpURLConnection httpConn = (HttpURLConnection)urlConn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
resCode = httpConn.getResponseCode();
if (resCode == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return in;
}
. 내가 뭘 잘못하고 있니? 어떤 도움을 더 주시면 감사하겠습니다.
AndroidManifest.xml 파일의 INTERNET 권한을 확인하십시오. –
예 인터넷 사용 권한이 AndroidManifest.xml 파일에 있습니다. – Larik