【发布时间】:2014-01-01 22:26:42
【问题描述】:
在我的 gridViewAdapter 中,我将 ImageResource 设置为 .png 对象,但它没有显示在活动中。这是适配器的getView函数:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.photoSubscriptTextView = (TextView) row.findViewById(R.id.photoSubscriptTextView);
holder.photoInstanceImageView = (ImageView) row.findViewById(R.id.galleryMonumentPhotoImageView);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
final Photo photo = data.get(position);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
if(photo.getPodpis().equals(getContext().getString(R.string.photo_add))){
intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
((Activity) context).startActivityForResult(Intent.createChooser(intent, "Select Picture"), 100);
}
else {
intent = new Intent(context, PhotoGallery.class);
intent.putExtra("photo", photo);
context.startActivity(intent);
}
}
});
holder.photoSubscriptTextView.setText(photo.getPodpis());
if(photo.getUri() != null)
aQuery.id(holder.photoInstanceImageView).image(photo.getUri());
else if(photo.getPodpis().equals(getContext().getResources().getString(R.string.photo_add))) {
holder.photoInstanceImageView.setImageResource(R.drawable.image_add);
}
return row;
还有xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:padding="5dp"
android:clickable="true"
android:focusable="true">
<!--android:background="@drawable/grid_color_selector"-->
<ImageView
android:id="@+id/galleryMonumentPhotoImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/image_add">
</ImageView>
<TextView
android:id="@+id/photoSubscriptTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:textSize="12sp" >
</TextView>
</LinearLayout>
主布局只包含Relative Layout和GridView。 谁能告诉我为什么我在适配器中设置的资源中的图像没有显示在活动中?
【问题讨论】:
标签: android gridview resources imageview gallery