android - 解析,安卓; ParseQuery 适配器中的 relation.getQuery()

标签 android parse-platform

在 ParseQueryAdapter 中,我想返回我正在查询的对象的关系。这是我目前所拥有的;我正在执行查询,检索当前用户创建的所有目标;在 public View getItemView 中,我开始获取对象(目标)的关系。我会创建一个 for 循环,并将结果存储在一个数组中吗?如果是这样,我该如何设置列表中的文本?非常感谢您的帮助!

public class GoalDetailViewAdapter extends ParseQueryAdapter<ParseObject> {

    protected ParseObject mPracticeName;



    public GoalDetailViewAdapter(Context context) {




        super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {

            public ParseQuery create() {
                // Here we can configure a ParseQuery to display
                // midwives
                ParseQuery<ParseObject> query = ParseQuery.getQuery("goal");
                query.whereEqualTo("createdby", ParseUser.getCurrentUser());

                return query;
            }
        });
    }



    @Override
    public View getItemView(ParseObject object, View view, final ViewGroup parent) {

        if (view == null) {
            view = View.inflate(getContext(), R.layout.activity_goal_detail_view, null);

        }

        //use midwifefirm as item view/list

        super.getItemView(object, view, parent);


        // find in layout the practice name
        TextView titleTextView = (TextView) view.findViewById(R.id.goalname);

        //in the midwifefirm data model, call getPracticename
        titleTextView.setText(object.getString("goalname"));


        TextView practiceTextView = (TextView) view.findViewById(R.id.practicename);

        ParseRelation relation = object.getRelation("practicerelation");


        relation.getQuery().findInBackground(new FindCallback() {
            @Override
            public void done(List list, ParseException e) {
                if (e !=null) {
                    //error

                }

                else {


                }
            }


        });



        /*mAddGoal = (ImageButton) view.findViewById(R.id.addgoal);
        mAddGoal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(parent.getContext(), AddGoal.class);
                v.getContext().startActivity(intent);
            }


        });*/

        return view;

最佳答案

好的,现在我了解了您的情况,我准备好给出答案了。

您需要做的(至少在我看来)是改变您与指针数组的关系。只要您不存储超过数百个指针,那么此设计应该不会出现明显的性能问题。

拥有指向关系的指针数组的巨大好处是它们可以直接包含在查询中。

现在你可以这样做:

public class GoalDetailViewAdapter extends ParseQueryAdapter<ParseObject> {

    protected ParseObject mPracticeName;



    public GoalDetailViewAdapter(Context context) {




        super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {

            public ParseQuery create() {
                // Here we can configure a ParseQuery to display
                // midwives
                ParseQuery<ParseObject> query = ParseQuery.getQuery("goal");
                query.whereEqualTo("createdby", ParseUser.getCurrentUser());

                // now all the pointers will be populated with data
                // once the query returns
                query.include("practicerelation");

                return query;
            }
        });
    }



    @Override
    public View getItemView(ParseObject object, View view, final ViewGroup parent) {

        if (view == null) {
            view = View.inflate(getContext(), R.layout.activity_goal_detail_view, null);

        }

        //use midwifefirm as item view/list

        super.getItemView(object, view, parent);


        // find in layout the practice name
        TextView titleTextView = (TextView) view.findViewById(R.id.goalname);

        //in the midwifefirm data model, call getPracticename
        titleTextView.setText(object.getString("goalname"));


        TextView practiceTextView = (TextView) view.findViewById(R.id.practicename);

        // now you can iterate the practices directly
        // note that this is not async no more         
        List<ParseObject> practices = object.getList("practicerelation")

        StringBuilder b = new StringBuilder();
        for (ParseObject practice: practices) {
            // assuming you have a 'step' col
            // this is just for the sake of example
            String step = practice.getString("step");
            b.append(step);
            b.append(",");
        }

        practiceTextView.setText(b.toString());

        return view;  

关于android - 解析,安卓; ParseQuery 适配器中的 relation.getQuery(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30111099/

相关文章:

android - 如何从 ParseUser 检索 authData?

java - 如何使用 Java 设置 AdUnitId?

Android 数字选择器键盘类型

android - 如何在 Google map 图像中绘制当前位置

android - 使用服务和 Singleton SQliteOpenHelper 进行数据隔离

ios 快速解析 : no results matched the query

android - Parse 服务器退役后,Parse4cn1 还能工作吗?

android - 特定项目使用哪个 MBaaS 平台 : Parse or Google Cloud

node.js - 如何使用 Parse Server 获取 JobStatus

android - ActionMode 背景不适用于 set support ActionBar with Toolbar