0

サーバーから画像を表示したい。実際には、段落を表示し、それとともに画像を表示する必要があります。これにはリスト ビューを選択しました。現在、段落を表示していますが、画像を表示しようとすると機能しません。これに関して私を助けてください...

私のコード:

private class ListAdapter extends ArrayAdapter<UserBO> { 
--
--
--
--  public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
            try {
                if (view == null) {
                    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    view = vi.inflate(R.layout.list_item, null);
                    // --CloneChangeRequired(list_item)
                }
                final UserBO listItem = mList.get(position); // --CloneChangeRequired
                if (listItem != null) {
--
--
--
--
imageUrl = "http://server.com//folder/"+ array.get(0);
((TextView) view.findViewById(R.id.description))
                            .setText(listItem.getdesc()));

downloadFile(imageUrl);
----
--
}
}
}
}

    void downloadFile(String fileUrl) {
        URL myFileUrl = null;
        try {
            myFileUrl = new URL(fileUrl);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            HttpURLConnection conn = (HttpURLConnection) myFileUrl
                    .openConnection();
            conn.setDoInput(true);
            conn.connect();
            int length = conn.getContentLength();
            InputStream is = conn.getInputStream();

            bmImg = BitmapFactory.decodeStream(is);
            imView.setImageBitmap(bmImg);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
4

2 に答える 2

0

どのようなエラーが発生していますか? スタック トレースを提供します。遅延読み込みも使用できますhttp://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/

于 2012-06-04T11:24:45.973 に答える
0

画像をダウンロードしてリストビューに表示するには、次のリンクのコードを使用します。

リストビューの遅延読み込み

于 2012-06-04T11:29:32.137 に答える