2011-10-25 3 views
0

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; 
    } 

. 내가 뭘 잘못하고 있니? 어떤 도움을 더 주시면 감사하겠습니다.

+0

AndroidManifest.xml 파일의 INTERNET 권한을 확인하십시오. –

+0

예 인터넷 사용 권한이 AndroidManifest.xml 파일에 있습니다. – Larik

답변

0

내 경험으로 볼 때, 안드로이드 개발자 블로그의이 게시물은 특히 멀티 스레딩 및 성능 문제와 관련하여 많은 도움이되었습니다. Multithreading for performance.

1

코드에 배경 이미지로드를 구현하지 않았으므로 Lazy Loading images in ListView을 사용하는 것이 좋습니다. 귀하의 경우에 가장 유용하다고 생각합니다. 스레딩 프로세스를 가져 오는 백그라운드 이미지를 구현하지 않으면 전체 데이터를 가져올 때 화면이 멈추고 실제 모드로 다시 해제됩니다. 지금은 이미지 뷰에 설정할 수 있도록 당신은 아마 BitmapFactory.decodeStream(inputstream);

를 사용한다

0

그래서 이것은 당신에게 비트 맵을 반환합니다.

희망이 도움이됩니다.

관련 문제