尝试从Android上的Parse和View调用图片

时间:2015-12-27 15:57:17

标签: java android parsing

我在MainActivity中有这个代码,它必须从Parse云中查看图像的图像和名称。我想在我的Parse数据库中查看带有文件名的图像。

 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;
            }
        };

enter image description here

这是我的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>

和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);
    }


    }

1 个答案:

答案 0 :(得分:0)

我可能会弄错,但您可能需要将图像转换为ParseFile,然后转换为位图,然后将其另存为imageview。 试一试

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);

        }
    });