Hi,
I have a table Exercises which is linked to the user as he/she can favorite an exercise. Now I’m trying to retrieve the user’s favorite exercises in my application.
I have a class Exercise with the getters and setters and in my main activity I want to show a list of the exercises. Using the documentation I got the following basic code:
Object[] favoritesObjectArray = (Object []) user.getProperty("exercise");
if (favoritesObjectArray != null && favoritesObjectArray.length > 0) {
Log.d("EXERCISE ", "- " + favoritesObjectArray[0]);
}
Using this code the first exercise gets logged perfectly, using a for-loop I’m able to get them all. Now how do I get these exercises in a listview? I’m able to do this for an ordinary BackendlessDataQuery using and a Custom List Adapter:
public class CatalogListAdapter extends ArrayAdapter<Exercise> {
private final Context mContext;
private final List<Exercise> mExercises;
public CatalogListAdapter(Context context, List<Exercise> objects) {
super(context, R.layout.list_item_catalog, objects);
this.mContext = context;
this.mExercises = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
convertView = mLayoutInflater.inflate(R.layout.list_item_catalog, parent, false);
}
Exercise exercise = mExercises.get(position);
TextView exerciseDescriptionView = (TextView) convertView.findViewById(R.id.exercise_description);
exerciseDescriptionView.setText(exercise.getTrainingExercise().replaceAll("\\\\u221A", "\u221A").replaceAll("\\\\n", "\n").replaceAll("\\\\u2265", "\u2265"));
TextView exerciseTotalView = (TextView) convertView.findViewById(R.id.exercise_total);
exerciseTotalView.setText(String.valueOf(exercise.getVolume()) + "m - ");
TextView exerciseAuthorView = (TextView) convertView.findViewById(R.id.author_name);
exerciseAuthorView.setText(exercise.getAuthor().getFirstname() + " " + exercise.getAuthor().getLastname());
return convertView;
}
}
catalogListAdapter = new CatalogListAdapter(this, new ArrayList<Exercise>());
ListView mListView = (ListView) findViewById(R.id.catalog_list_view);
mListView.setAdapter(catalogListAdapter);
Backendless.Persistence.of(Exercise.class).find(backendlessDataQuery, new AsyncCallback<BackendlessCollection<Exercise>>() {
@Override
public void handleResponse(BackendlessCollection<Exercise> exerciseBackendlessCollection) {
mProgressBar.setVisibility(View.GONE);
for (Exercise exercise : exerciseBackendlessCollection.getCurrentPage()) {
catalogListAdapter.add(exercise);
}
}
// TODO: handle fault
@Override
public void handleFault(BackendlessFault backendlessFault) {
}
});
Ofcourse this code is not complete but you get the point. But returning user properties appears to be done in a different way and I can’t get it working. Any help would be greatly appreciated!
Cheers