我正在尝试从解析中的.txt文件中获取文本并将其转换为String并将文本放在textview中。我试着通过像图像一样的方式进行研究(AppetizerRecipe.java)
从图像中可以看出,我有一个由txt文件组成的列“配方”。 logcat显示该文件是从解析中检索的,当我点击它时,它会显示我的文件。我似乎无法将文本放到我的textview上。任何帮助将不胜感激。
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
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());
}
}
});
答案 0 :(得分:1)
从String
获得byte[]
:
//your byte[] being data
String str = new String(data);
然后在String
上设置TexView
,如:
textView.setText(str);