0
我試圖加載圖像到RecyclerView Adapater我得到的錯誤與將圖像載入RecyclerViewAdapter
如果(照片!= NULL) - 意外的標記。
return newPhotoFilterViewHolder(view); - 無效的聲明返回類型必需。
public class PhotoFiltersAdapter extends RecyclerView.Adapter - 聲明抽象或創建抽象方法。
這裏是我的實現代碼,以圖像加載到RecyclerViewAdapter
public class PhotoFiltersAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private int itemsCount = 12;
ImageView image;
// Fields for the map radius in feet
private float radius = InstaMaterialApplication.getSearchDistance();
/**
* Helper class to get the user location.
*/
private GeoLocationHelper geoLocationHelper = new GeoLocationHelper();
// Adapter for the Parse query
private ParseQueryAdapter<FilterImages> postsQueryAdapter;
public PhotoFiltersAdapter(Context context) {
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(final FilterImages post, ViewGroup parent, int viewType) {
final View view = LayoutInflater.from(context).inflate(R.layout.item_photo_filter, parent, false);
// Set up the query adapter
postsQueryAdapter = new ParseQueryAdapter<FilterImages>(this, factory) {
ParseFile photo = (ParseFile) post.get("image");
if(photo!=null)
{
photo.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
// TODO Auto-generated method stub
if (data != null && e == null) {
Bitmap bitmap = BitmapFactory
.decodeByteArray(data, 0,
data.length);
image.setImageBitmap(bitmap);
} else {
//ParseException e
}
}
});
}
else
{
//picture_not_available
}
TextView contentView = (TextView) view.findViewById(R.id.content_view);
ImageView image=(ImageView)view.findViewById(R.id.picture_view);
TextView usernameView = (TextView) view.findViewById(R.id.username_view);
contentView.setText(post.getText());
return newPhotoFilterViewHolder(view);
};
}
private ParseGeoPoint geoPointFromLocation(Location loc) {
return new ParseGeoPoint(loc.getLatitude(), loc.getLongitude());
}
// Set up a customized query
ParseQueryAdapter.QueryFactory<FilterImages> factory =
new ParseQueryAdapter.QueryFactory<FilterImages>() {
public ParseQuery<FilterImages> create() {
Location myLoc = geoLocationHelper.getCurrentLocation();
ParseQuery query = FilterImages.getQuery();
query.include("PlaceName");
query.orderByDescending("AreaFilters");
query.whereWithinKilometers("AreaFilters", geoPointFromLocation(myLoc), radius);
query.setLimit(itemsCount);
return query;
}
};
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
}
@Override
public int getItemCount() {
return itemsCount;
}
public static class PhotoFilterViewHolder extends RecyclerView.ViewHolder {
public PhotoFilterViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
}