繁体   English   中英

Android如何使用ParseQueryAdapter在列表中仅显示特定用户的数据

[英]Android how to display data of only a particular user in list using ParseQueryAdapter

我有一个名为trips的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;
    }

但是当我运行该应用程序时,我能够看到所有用户创建的数据。 我该如何解决 ? 谢谢

我正在做非常相似的事情,并且正在工作。 我唯一看到的区别是在这一行

ParseQuery query = new ParseQuery("Trips");

除此之外,我做了相当于

ParseQuery<Trips> query = ParseQuery.getQuery(Trips.class);
query.include("user"); // Don't think this will matter

让我知道这个是否奏效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM