在ParseQueryAdapter中,我想返回我正在查询的对象的关系。这就是我到目前为止所拥有的;我正在执行查询,检索当前用户创建的所有目标;在公共视图中getItemView我开始得到对象(目标)的关系。我会创建一个for循环,并将结果存储在一个数组中吗?如果是这样,我怎么能在列表中设置文本?非常感谢你的帮助!
sincedate
答案 0 :(得分:1)
好的,既然我了解你的情况,我准备回答。
你需要做什么(至少在我看来)是改变你与一系列指针的关系。只要您不存储超过100个指针,那么此设计应该没有明显的性能问题。
在关系上有一组指针的巨大好处是它们可以直接包含在查询中。
现在你可以这样做:
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;