我试图在我的项目中使用ParseQueryAdapter,并且没有任何运气来显示结果。
我的目标是从ParseUser获取数据。因此,我的模型扩展了ParseUser:
所以我有一个模型:
@ParseClassName("Midwifefirm")
public class Midwifefirm extends ParseUser {
public Midwifefirm() {
// A default constructor is required.
}
//practice name
public String getPracticeName() {
return getString("practicename");
}
public void setPracticeName(String title) {
put("title", title);
}
//education
public String getEducation() {
return getString("education");
}
public void setEducation(String education) {
put("education", education);
}
//years in practice
public String getYearsinPractice() {
return getString("yearsinpractice");
}
public void setYearsinPractice(String yearsinpractice) {
put("yearsinpractice", yearsinpractice);
}
//practice philosophy
public String getPracticePhilosophy() {
return getString("practicephilosophy");
}
public void setPracticePhilosophy(String practicephilosophy) {
put("practicephilosophy", practicephilosophy);
}
适配器在这里;我认为问题可能出在我的查询中:
public class CustomMidwifeAdapter extends ParseQueryAdapter<Midwifefirm> {
public CustomMidwifeAdapter(Context context) {
//query using Midwifefirm class, to get list of midwives
super(context, new ParseQueryAdapter.QueryFactory<Midwifefirm>() {
public ParseQuery<Midwifefirm> create() {
ParseQuery query = new ParseQuery("Midwifefirm");
query.whereEqualTo("userType", "midwife");
return query;
}
});
}
@Override
public View getItemView(Midwifefirm midwifefirm, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(getContext(), R.layout.activity_midwife_result_list, null);
}
//use midwifefirm as item view/list
super.getItemView(midwifefirm, view, parent);
// find in layout the practice name
TextView titleTextView = (TextView) view.findViewById(R.id.practicename);
//in the midwifefirm data model, call getPracticename
titleTextView.setText(midwifefirm.getPracticeName());
// Add education view
TextView EducationView = (TextView) view.findViewById(R.id.education);
EducationView.setText(midwifefirm.getEducation());
// Add yearsexperience view
TextView ExperienceView = (TextView) view.findViewById(R.id.yearsinpractice);
ExperienceView.setText(midwifefirm.getYearsinPractice());
//Add practice philosophy view
TextView PracticePhilosophyView = (TextView) view.findViewById(R.id.practicephilosophy);
PracticePhilosophyView.setText(midwifefirm.getPracticePhilosophy());
return view;
}
}
这是我的ListView;
public class MidwifeResultList extends ListActivity {
private ParseQueryAdapter<Midwifefirm> mainAdapter;
private CustomMidwifeAdapter midwifeListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set display to listview, empty
getListView().setClickable(false);
//initialize main ParseQueryAdapter
mainAdapter = new ParseQueryAdapter<Midwifefirm>(this, Midwifefirm.class);
mainAdapter.setTextKey("practicename");
mainAdapter.setTextKey("education");
mainAdapter.setTextKey("yearsinpractice");
mainAdapter.setTextKey("practicephilosophy");
// Initialize the subclass of ParseQueryAdapter
midwifeListAdapter = new CustomMidwifeAdapter(this);
setListAdapter(mainAdapter);
// Initialize ListView and set initial view to mainAdapter
// listView = (ListView) findViewById(R.id.lvMidwives);
// listView.setAdapter(mainAdapter);
// mainAdapter.loadObjects();
}
}
我可能将其设置为错误..感谢您的任何见识。
最佳答案
仅查看您提供的内容,我认为这与您的查询有关。您正在查询键“ userType”,但子类Midwifefirm似乎没有该键。
编辑
要回答您的评论,您将使用以下查询获取所有助产士对象:
ParseQuery<Midwifefirm> query = ParseQuery.getQuery(Midwifefirm.class);
/* add any additional constraints to your query here */
query.findInBackground(new FindCallback<Midwifefirm>() {
@Override
public void done(List<Midwifefirm> results, ParseException e) {
}
}
我相信Parse对单个查询100可以获取的对象数量有一定的限制,因此您可能必须研究增加方法来满足需求的方法。
关于android - ParseQueryAdapter,不显示结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29974952/