从parse.com接收文本文件并将其放置在textview中 [英] Receive text file from parse.com and place in textview

查看:87
本文介绍了从parse.com接收文本文件并将其放置在textview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Parse中的文本文件中获取文本并将其转换为String并将文本放置在textview中.我尝试通过与图像(AppetizerRecipe.java)相同的方式进行研究时建议的人

I am trying to get the text from a text file in Parse and convert it to String and place the text in a textview. I tried doing what someone suggested while researching by doing it the same way as an image (AppetizerRecipe.java)

从图像中可以看到,我有一列食谱",其中包含文本文件. Logcat显示文件是从解析中检索的,当我单击它时,它显示了我的文件.我似乎无法将文本显示在textview上.

As you can see from the images, i have a column "recipe" that consists of text files. The logcat shows that the file is retrieved from parse and when I click on it, it shows me my file. I can't seem to get the text onto my textview.

onListItemClick:

onListItemClick:

@Override
protected void onListItemClick(ListView l, View v, int position, long
        id) {
    super.onListItemClick(l, v, position, id);

    ParseObject po = mAppetizers.get(position);

    ParseFile recipes = po.getParseFile("recipe");


    // TODO: Get fields from Parse
    String title = po.getString(AppetizerRecipe.ARG_NAME);
    String time = po.getString(AppetizerRecipe.ARG_TIME);
    String ID = po.getObjectId().toString();
        Log.d("Appetizer", "object: " + ID);

    Intent intent = new Intent(Appetizer.this, AppetizerRecipe.class);

    // TODO: Put extras
    intent.putExtra(AppetizerRecipe.ARG_NAME, title);
    intent.putExtra(AppetizerRecipe.ARG_TIME, time);
    intent.putExtra("ID", ID);
        Log.d("Appetizer", "object: " + ID);


    startActivity(intent); // TODO:  In other activity, get these extras
}

AppetizerRecipe.java

AppetizerRecipe.java

ParseQuery<ParseObject> gettext = new ParseQuery<>("Appetizers"); 
    gettext.addAscendingOrder("appetizer"); 
    gettext.whereEqualTo("ID", ID); 
    gettext.getInBackground(ID, new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject textobject, ParseException e) {
            if (e == null) {
                // success
                final ParseFile textObject = (ParseFile) textobject.get("recipe");
                textObject.getDataInBackground(new GetDataCallback() {
                    public void done(byte[] data, ParseException e) {
                        if (e == null) {
                            // use data for something

                        } else {

                        }
                    }
                });

            } else {
                // fail
                Log.d("test", "Error Message..." + e.getMessage());
            }
        }
    });

parse.com:

parse.com:

Logcat:

来自parse.com的文本文件:

Text file from parse.com:

推荐答案

要从byte[]获取String:

//your byte[] being data
String str = new String(data);

,然后在TexView上将String设置为:

textView.setText(str);

这篇关于从parse.com接收文本文件并将其放置在textview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆