【发布时间】:2019-10-08 07:15:42
【问题描述】:
简单的switch 语句,带有下一步按钮作为最后一个案例。我想要它,所以用户必须在 switch 语句中选择一个图像,然后再继续。我不知道如何编写一些东西来阻止他们用户只需单击下一个按钮并移动到下一个活动而不从 switch 语句中进行选择。代码如下。
public void onClick(View v) {
SharedPreferences.Editor editorWorkout = workoutPref.edit();
// get the constraint layout from its ID.
ConstraintLayout mConstraintLayout = getView().findViewById(R.id.FragmentWorkoutMood1);
switch (v.getId()) {
case R.id.excitedFace:
mConstraintLayout.setBackgroundResource(R.mipmap.background_clouds_excited);
editorWorkout.putInt("excitedkey", EXCITED.getId());
editorWorkout.commit();
break;
case R.id.happyFace:
mConstraintLayout.setBackgroundResource(R.mipmap.background_clouds_happy);
editorWorkout.putInt("happykey", HAPPY.getId());
editorWorkout.commit();
break;
case R.id.fineFace:
mConstraintLayout.setBackgroundResource(R.mipmap.background_clouds_fine);
editorWorkout.putInt("finekey", FINE.getId());
editorWorkout.commit();
break;
case R.id.nextBtnMoodPage:
Intent intent = new Intent(getActivity(), WorkoutAutomaticThoughtActivity.class);
startActivity(intent);
}
【问题讨论】:
-
您在实施过程中遇到了什么问题?
-
我不知道如何写一些东西来阻止他们用户只需单击下一个按钮并移动到下一个活动而不从 switch 语句中进行选择
-
在
case R.id.nextBtnMoodPage:之后尝试break;并调试并检查它是否仍然属于任何情况? -
case R.id.nextBtnMoodPage: Intent intent = new Intent(getActivity(), WorkoutAutomaticThoughtActivity.class); startActivity(intent); break; -
感谢您的帮助,但也许您没有正确理解我的问题。在选择下一个按钮之前,用户必须从开关状态中选择一个图像,如 R.id.happyface。目前,用户只需单击下一步按钮并继续前进,而无需选择图像。这有意义吗?
标签: java android android-switch