我有一个名为trip的parseobject。我想显示特定用户的行程数据,该用户仅在片段中的任何时间点登录,而不是整个行程表。我正在使用以下代码;
public class TripListAdapter extends ParseQueryAdapter<Trips> {
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyy");
public TripListAdapter(Context context) {
super(context, new ParseQueryAdapter.QueryFactory<Trips>() {
public ParseQuery<Trips> create() {
// Here we can configure a ParseQuery to display
// only top-rated meals.
ParseUser currentUser = ParseUser.getCurrentUser();
ParseQuery query = new ParseQuery("Trips");
query.whereEqualTo("user", currentUser);
//query.whereContainedIn("rating", Arrays.asList("5", "4"));
query.orderByDescending("createdAt");
return query;
}
});
}
@Override
public View getItemView(Trips trips, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.item_trip_list, null);
}
super.getItemView(trips, v, parent);
//ParseImageView mealImage = (ParseImageView) v.findViewById(R.id.icon);
//ParseFile photoFile = meal.getParseFile("photo");
//if (photoFile != null) {
//mealImage.setParseFile(photoFile);
//mealImage.loadInBackground(new GetDataCallback() {
//@Override
//public void done(byte[] data, ParseException e) {
// nothing to do
// }
//});
//}
TextView destinationTextView = (TextView) v.findViewById(R.id.trip_destination);
destinationTextView.setText(trips.getDestination());
TextView durationTextView = (TextView)v.findViewById(R.id.trip_duration);
durationTextView.setText(formatter.format(trips.getStartDate())+" - "+formatter.format(trips.getEndDate()));
return v;
}
但是当我运行应用程序时,我能够看到所有用户创建的数据。我该如何解决 ? 谢谢
答案 0 :(得分:0)
我正在做一些非常相似的事情,而且它正在发挥作用。我能看到的唯一区别就是这一行
ParseQuery query = new ParseQuery("Trips");
而不是我做了相同的
ParseQuery<Trips> query = ParseQuery.getQuery(Trips.class);
query.include("user"); // Don't think this will matter
让我知道这是否有效。