gpt4 book ai didi

android - 显示查询结果 Parse.com android

转载 作者:太空狗 更新时间:2023-10-29 14:56:06 25 4
gpt4 key购买 nike

我有一个问题,这听起来像是一个愚蠢的问题,但我真的不知道如何回答并且需要一个答案。

在parse.com查询完成后,如何显示结果

比如这个

ParseQuery<ParseObject> gameQuery = ParseQuery.getQuery("Game");
gameQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());

我想在我的应用程序中将查询结果设置为某个 TextView :textview.setText(??);

提前谢谢你:)

编辑:

这是我正在使用的代码

public class Adapter extends ParseQueryAdapter<ParseObject> {
//MediaPlayer mediaPlayer;

public Adapter(Context context) {

super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Game");
return query;
}
});
}

// Customize the layout by overriding getItemView
@Override
public View getItemView(final ParseObject object, View v, ViewGroup parent) {

if (v == null) {
v = View.inflate(getContext(), R.layout.list_item, null);
}

super.getItemView(object, v, parent);

// I'm getting Images from Game class
ParseImageView audioImage = (ParseImageView) v.findViewById(R.id.list_image);
ParseFile imageFile = object.getParseFile("img");
if (imageFile != null) {
audioImage.setParseFile(imageFile);
audioImage.loadInBackground();
}//end if


//retrieving Titles from Game Class
TextView titleTextView = (TextView) v.findViewById(R.id.list_title);
titleTextView.setText(object.getString("title"));


//Now I want to retrieve name from User Class :(
// the code is crashing my app
//?????????????????????????????????????????????????

ParseQuery<ParseObject> userQuery = ParseQuery.getQuery("Game");
userQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
userQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, com.parse.ParseException e) {

if (e == null) {
ParseObject userName = list.get(0); // Gets first object

// You can get fields using the get() method
ParseUser user = (ParseUser) userName.get("createdBy");

// There are data specific methods as well
String firstName = user.getString("name");

nameTextView.setText(firstName);
} else {
Log.d("score", "Error: " + e.getMessage());
}
}

});





return v;
}//end getItem View

}//end custom Adapator

最佳答案

ParseQuery<ParseObject> gameQuery = ParseQuery.getQuery("Game");
gameQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
gameQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> gameList, ParseException e) {
if (e == null) {
ParseObject game = gameList.get(0); // Gets first object

// You can get fields using the get() method
ParseUser user = game.get("createdBy");

// There are data specific methods as well
String firstName = user.getString("userFirstName");

textview.setText(firstName);
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});

以上仅为示例。查看documentation ParseObject 用于从对象获取数据的所有 get*() 方法。

常见的有:get()getString()getBoolean

更新:

首先,您必须告诉您的查询也获取指针数据(默认情况下,Parse 不包括用于查询的指针数据)。这就是您的应用程序崩溃的原因。因此,将您的查询更新为:

ParseQuery<ParseObject> userQuery = ParseQuery.getQuery("Game");
userQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
userQuery.include("createdBy");

更新 2:

public class Adapter extends ParseQueryAdapter<ParseObject> {
//MediaPlayer mediaPlayer;

public Adapter(Context context) {

super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Game");
userQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
query.include("createdBy");
return query;
}
});
}

// Customize the layout by overriding getItemView
@Override
public View getItemView(final ParseObject object, View v, ViewGroup parent) {

if (v == null) {
v = View.inflate(getContext(), R.layout.list_item, null);
}

super.getItemView(object, v, parent);

// I'm getting Images from Game class
ParseImageView audioImage = (ParseImageView) v.findViewById(R.id.list_image);
ParseFile imageFile = object.getParseFile("img");
if (imageFile != null) {
audioImage.setParseFile(imageFile);
audioImage.loadInBackground();
}//end if


//retrieving Titles from Game Class
TextView titleTextView = (TextView) v.findViewById(R.id.list_title);
titleTextView.setText(object.getString("title"));


//Now I want to retrieve name from User Class :(
// the code is crashing my app
//?????????????????????????????????????????????????

// You can get fields using the get() method
ParseUser user = (ParseUser) object.get("createdBy");

// There are data specific methods as well
String firstName = user.getString("name");

nameTextView.setText(firstName);

return v;
}//end getItem View

}//end custom Adapator

关于android - 显示查询结果 Parse.com android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31290583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com