2016-05-30 2 views
0

私はムービーデータベース(ムービーオブジェクトに格納されている)にオンラインで画像へのパスを提供するイメージがあります。これらのイメージをダウンロードしてカスタムArrayAdapterで表示したいのですが、イメージIDで参照するイメージをダウンロードする方法がわかりません。ここにコードがあります。ダウンロードしたイメージをintイメージIDに変換する方法(ArrayAdapterで使用する場合)?

タイトルを含む、映画を表し、クラス、インターネット経由でダウンロードするためのposterpath、posterImgための整数(これを見つける方法がわからない)ローカルにダウンロード:

public class Movie { 
    protected String id; 
    protected String posterPath; 
    protected String title; 
    //TODO pass in image reference 
    protected int posterImg; 
    private final String LOG_TAG = Movie.class.getSimpleName(); 

    public Movie(String id, String posterPath, String title){ 
     this.posterPath = posterPath; 
     this.id = id; 
     this.title = title; 
    } 

    public String getId() { 
     return id; 
    } 

    public String getPosterPath() { 
     return posterPath; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public int getPoster() { return posterImg; } 
} 

カスタムArrayAdapterのみいくつかのメソッドを持ちます:

public class MovieAdapter extends ArrayAdapter<Movie> { 
    private static final String LOG_TAG = MovieAdapter.class.getSimpleName(); 

    public MovieAdapter(Activity context, List<Movie> movies){ 
     super(context, 0, movies); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
     Movie movie = getItem(position); 

     if(convertView == null){ 
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_movie, parent, false); 
     } 

     ImageView iconView = (ImageView) convertView.findViewById(R.id.list_item_icon); 
     iconView.setImageResource(movie.getPoster()); 

     TextView titleView = (TextView) convertView.findViewById(R.id.list_item_title); 
     titleView.setText(movie.getTitle()); 

     return convertView; 
    } 
} 

この方法を使用してこれらの画像をインポートして表示する方法を教えてください。私はLazyListライブラリのようなものを見回しましたが、プロジェクトにインポートする方法を理解できませんでした。私はまた、この方法を使用してこれを行う方法を知りたいと思います。

ありがとうございました。

答えて

0

グライドを使用すると、1行のコードで画像のダウンロード、キャッシュ、表示をすべて処理できます。 idsを処理する必要はありません。

ImageView targetImageView =(ImageView)findViewById(R.id.imageView);

String internetUrl = "http://i.imgur.com/DvpvklR.png";

グライド .with(context) .load(internetUrl) .into(targetImageView);

https://futurestud.io/blog/glide-getting-started

ここでそれについての詳細を読みます
関連する問題