2017-06-04 18 views
0

私のアプリケーションでビットマップのサイズ変更を行っています。 Bitmap Imagesというフォルダがあり、ビットマップのサイズ変更を開始する機能があります。しかし、私のアダプタ(このコード行)でhold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(getResources(),news[position].Image,100,100));、最初のパラメータgetResourceがエラーとして発生します。何が欠けている?BitMapイメージの読み込み - Xamarin.Andoird

public class MyAdapter : RecyclerView.Adapter 

    { 
     private JavaList<News> news; 



     public MyAdapter(JavaList<News> news) 
     { 
      this.news = news; 

     } 

     //binding data to views 
     public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) 
     { 
      MyHolder hold = holder as MyHolder; 
      hold.Comment.Text = news[position].Comment; 
      //hold.Img.SetImageResource(news[position].Image); 
      hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(getResources(),news[position].Image,100,100)); 


     } 
+0

あなたのエラー – Yupi

+0

@Yupiを投稿するリソースがすでに – XamarinDevil

答えて

0

問題はContextを渡していないことです。 getResources()にアクセスするには、Contextに合格する必要があります。したがって、アダプタクラスを変更してください。

public class MyAdapter : RecyclerView.Adapter 

{ 
    private JavaList<News> news; 
    private Context context; 



    public MyAdapter(JavaList<News> news, Context context) 
    { 
     this.news = news; 
     this.context = context; 
    } 

    ...... 
//Then in your OnBindViewHolder you can call getResources 
    ..... 
    hold.Img.SetImageBitmap(BitmapImages.decodeSampledBitmapFromResource(context.getResources(),news[position].Image,100,100)); 
} 
+0

'Context.getResourceは()'また、この後の私の編集した答え – XamarinDevil

+0

受け付けられません下線されているので、私はまだアプリを実行していませんクラスのコンストラクタでContextが提供されるように、 'MyAdapter'クラスのインスタンスを作成するコンテキストを提供する必要があります。 – Yupi

+0

あなたは意志を参照してください – Yupi

関連する問題