holder.item3.setImageResource(custom.getcustomImage());
これはListViewAdapter
、イメージビューを保持するカスタムのコード行です。ImageView
.内のサイズに縮小するために入れた画像を取得する必要がありListView
ます。
アダプターのアイテムに適用したいのですimageview.setImageResource(custom.getcustomImage());
が、エラーが発生します。
Cannot invoke setScaleType(ImageView.ScaleType) on the primitive type int
私のコードは次のようになります
holder.item3.setImageResource(custom.getcustomImage().setScaleType(ScaleType.FIT_XY);
これをどのように使用すると思いますか?また、画像を私の 内にFIT_XY
収める別の方法はありますか?ImageView
ListView
私のアダプター。
public class CustomAdapter extends ArrayAdapter<Custom> {
private ArrayList<Custom> entries;
private Activity activity;
public CustomAdapter(Activity a, int textViewResourceId,
ArrayList<Custom> entries) {
super(a, textViewResourceId, entries);
this.entries = entries;
this.activity = a;
// TODO Auto-generated constructor stub
}
public class ViewHolder {
public TextView item1;
public TextView item2;
public ImageView item3;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
LayoutInflater vi = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.rowlayout, null);
holder = new ViewHolder();
holder.item1 = (TextView) v.findViewById(R.id.secondLine);
holder.item2 = (TextView) v.findViewById(R.id.firstLine);
holder.item3 = (ImageView) v.findViewById(R.id.icon);
v.setTag(holder);
} else
holder = (ViewHolder) v.getTag();
final Custom custom = entries.get(position);
if (custom != null) {
holder.item1.setText(custom.getcustomBig());
holder.item2.setText(custom.getcustomSmall());
holder.item3.setImageResource(custom.getcustomImage());
holder.item3.setScaleType(ScaleType.FIT_XY);
}
return v;
}
}
}
ラインコーリングコード
a = new Custom("String one","Stringtwo", R.drawable.image);
行のレイアウト
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="#FFFFFF"
android:padding="6dip" >
<!-- android:background="@color/Cream" -->
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
android:src="@drawable/launchicon" />
<TextView
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/icon"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Example application"
android:textColor="#000000"
android:textSize="12sp" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/icon"
android:gravity="center_vertical"
android:text="Description"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>