I have this code in my MainActivity it has to view Image and Name of the Image from Parse cloud. I want to view the image with its file name which is there on my Parse Database.
postsQueryAdapter = new ParseQueryAdapter<ParseConfig>(this, factory) {
@Override
public View getItemView(ParseConfig post, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(getContext(), R.layout.filter_view, null);
}
ImageView contentView = (ImageView) view.findViewById(R.id.content_view);
TextView usernameView = (TextView) view.findViewById(R.id.username_view);
contentView.setText();post.getImage().getFile());
usernameView.setText(post.getUser().getUsername());
return view;
}
};
Here is my filter_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/content_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/username_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
And the ParseConfig.java
public class ParseConfig extends ParseObject {
public void setFile(Bitmap value) {
put("FilterFile",value);
}
public ParseUser getUser() {
return getParseUser("user");
}
public ParseFile getImage() {
return getParseFile("FilterFile");
}
public ParseGeoPoint getLocation() {
return getParseGeoPoint("PlaceLocation");
}
public static ParseQuery<ParseConfig> getQuery() {
return ParseQuery.getQuery(ParseConfig.class);
}
}
I could be mistaken but you may have to cast the image as a ParseFile, and then convert to bitmap and then save it as an imageview. give this a try
ParseFile img = (ParseFile) post.getImage("YourImageNameOnDatabase").getFile());
img.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Bitmap bit = BitmapFactory.decodeByteArray(data, 0, data.length);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bit.compress(Bitmap.CompressFormat.PNG, 100, stream);
contentView.setImageBitmap(bit);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.