カスタムレイアウトをlistviewに反映させたいです。
名前、職業、画像のデータを表示させたいので、MemberProfileクラスを作りました。
で、画像を設定したいのですが、型が合わない?とエラーになっています。
Bitmapの型を指定するにはどうしたらいいのでしょうか?
MemberProfile.java
import android.graphics.Bitmap; public class MemberProfile { // 宣言 private String name; private String job; private Bitmap image; //コンストラクタの生成 public MemberProfile(String name, String job, Bitmap image){ super(); this.name = name; this.job = job; this.image = image; } //ゲッターの設定 public String getName(){ return this.name; } public String getJob(){ return this.job; } public Bitmap getImage(){ return this.image; } }
カスタムアダプタークラス
ublic class CustomAdapter extends ArrayAdapter<MemberProfile> { //CustomAdapterのコンストラクター public CustomAdapter(Context context, List<MemberProfile> objects) { super(context, R.layout.custom_list2, R.id.text, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { //カスタムレイアウトをviewの中で保持 View view = super.getView(position, convertView, parent); TextView text = (TextView)view.findViewById(R.id.text); TextView text2 = (TextView)view.findViewById(R.id.text2); ImageView image = (ImageView) view.findViewById(R.id.image); MemberProfile memberProfile = getItem(position); // text.setText(memberProfile.getName()); text2.setText(memberProfile.getJob()); image.setImageBitmap(memberProfile.getImage()); return view; } }
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。