gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 20:47:01 25 4
gpt4 key购买 nike

在 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/

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