好吧,这个问题已经被困了好几个星期了,很抱歉这个问题太长了。
使用 Parse,制作适用于 Android 的锻炼应用程序。
与我的问题相关的数据库表和列是:
练习
身份证| 姓名 | 描述 | 肌肉群
锻炼
身份证| 锻炼名称| 用户身份
WorkoutExercises(基本上是两者之间的连接表)
身份证| 锻炼ID(指针)| 练习ID(指针)
因此,用户将能够创建锻炼并添加他们想要的锻炼。
到目前为止,我已经完成了:
- 用户可以去分类,浏览肌肉群,查看该群的练习
- 注册/登录/注销,更新个人资料
- 列出当前的锻炼(不是其中的锻炼) - 我刚刚在数据库上的锻炼中输入了一些锻炼,因为在担心插入新锻炼之前,我一直在查询该锻炼中的当前锻炼。
问题:
我正在尝试进行嵌套查询以获取练习名称,因此一旦用户单击 Eg。Back 锻炼它应该会显示一个列表,例如。硬拉、划船、引体向上
所以基本上在 SQL 中我想:
从 ID 所在的练习中选择名称(从 WorkoutID=xxxx 的锻炼锻炼中选择锻炼ID)
我正在努力的事情:
根据我在网上阅读的内容,对指针进行嵌套查询,我需要使用 query.include("exerciseID"); 它将告诉 Parse 包含一个完整的练习项目,然后我可以使用它来查询?如果错了纠正我?下面的代码 - 我做对了吗?
我已经从中学习并使用了以下方法:http: //www.michaelevans.org/blog/2013/08/14/tutorial-building-an-android-to-do-list-app-using-parse/其中查询数据被放入列出数据的自定义适配器中。它使用 getter 和 setter 来保存/检索 String/int 值,我是否仍然使用 getter 从指针中获取字符串?
例如。
public String getName()
{
return getString("name");
}
就像一旦我“通过”那个指针并且在练习表中我假设我仍然只是获取字符串名称值而不是获取 ParseObject?
现在到目前为止,我已经能够让自定义适配器在屏幕上放置 2 个水平条,表明它知道我已经在锻炼练习中放置了 3 个项目,但只是没有从嵌套查询中显示我需要的练习名称中的文本
看看我的截图,看看我的意思。
非常感谢您提前提供的帮助。
查询至今:
public void getcurrentExercisesInWorkout() {
//set progress bar
setProgressBarIndeterminateVisibility(true);
ParseQuery<WorkoutExercises> query = ParseQuery.getQuery("WorkoutExercises");
query.include("exerciseId");
query.whereEqualTo("workoutId", mWorkoutId);
query.findInBackground(new FindCallback<WorkoutExercises>() {
@Override
public void done(List<WorkoutExercises> workoutExercises, ParseException error) {
if (workoutExercises != null) {
mWorkoutExercisesAdapter.clear();
mWorkoutExercisesAdapter.addAll(workoutExercises);
} else {
Log.d("error", error.getMessage());
}
}
});
//stop progress bar
setProgressBarIndeterminateVisibility(false);
}
自定义列表适配器:
//constructor - get current state of parsed object and list of objects retrieved from workout
public WorkoutExercisesAdapter(Context context, List<WorkoutExercises> objects) {
super(context, R.layout.row_item, objects);
this.mContext = context;
this.mWorkoutExercises = objects;
}
public View getView(int position, View convertView, ViewGroup parent)
{
//put each item into the listview
if(convertView == null)
{
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
convertView = mLayoutInflater.inflate(R.layout.row_item,null);
}
WorkoutExercises workoutExercises = mWorkoutExercises.get(position);
TextView nameView = (TextView) convertView.findViewById(R.id.row_name);
//this just calls a String getter - which isn't working - need it to get the Exercise name from within the pointer
nameView.setText(workoutExercises.getWorkoutExercise());
return convertView;
}
WorkoutExercises(存储吸气剂)
@ParseClassName("WorkoutExercises")
public class WorkoutExercises extends ParseObject {
public String exName;
public WorkoutExercises()
{
}
public String getWorkoutExercise()
{
return getString("name");
}
}
在调试模式下运行 Android Studio 我可以从字面上看到我试图放入文本字段的数据(见截图 - 我如何获取该值?见下面的截图
现在工作 - 结果!