当我的用户第一次登陆主要活动时,我希望图块(图像视图)显示为灰色且不可点击。只有第一个图块应为彩色且可点击。用户访问第一个图块并返回到主要活动后,下一个图块将变为彩色并可单击,依此类推。
这个想法是在第一次使用该应用程序时引导用户进行操作的顺序。我想此信息将需要存储在共享首选项中,因为我只希望第一次发生这种情况。随后,所有图块均应为彩色且可点击。
有人可以帮助我实现这一目标吗?目前,我有一个switch语句,图像图块的布尔值和彩色/灰色版本。
@Override
public void onClick(View v) {
SharedPreferences.Editor introEditor = introPref.edit();
switch (v.getId()) {
case R.id.cbt_button_grey:
Intent mainIntent = new Intent(getActivity(), IntroActivity2.class);
startActivity(mainIntent);
hasSelected = true;
introEditor.putBoolean("hasSelected", hasSelected);
introEditor.commit();
break;
case R.id.twisted_thinking_button_grey:
hasSelected = true;
Intent distortedIntent = new Intent(getActivity(), TwelveTypesDistortedThinkingSliderActivity.class);
startActivity(distortedIntent);
break;
case R.id.workout_button_grey:
hasSelected = true;
Fragment workoutFragment = new WorkoutFragment();
FragmentTransaction workoutTransaction = getActivity().getSupportFragmentManager().beginTransaction();
workoutTransaction.replace(R.id.fragment_container, workoutFragment);
workoutTransaction.commit();
break;
case R.id.workout_log_button_grey:
hasSelected = true;
Fragment workoutLogFragment = new WorkoutLogFragment();
FragmentTransaction workoutLogTransaction = getActivity().getSupportFragmentManager().beginTransaction();
workoutLogTransaction.replace(R.id.fragment_container, workoutLogFragment);
workoutLogTransaction.commit();
break;
case R.id.mood_log_button:
hasSelected = true;
Fragment moodLogFragment = new MoodLogFragment();
FragmentTransaction moodLogTransaction = getActivity().getSupportFragmentManager().beginTransaction();
moodLogTransaction.replace(R.id.fragment_container, moodLogFragment);
moodLogTransaction.commit();
break;
case R.id.activities_button_grey:
hasSelected = true;
Fragment activitiesFragment = new ActivitiesFragment();
FragmentTransaction activitiesTransaction = getActivity().getSupportFragmentManager().beginTransaction();
activitiesTransaction.replace(R.id.fragment_container, activitiesFragment);
activitiesTransaction.commit();
break;
}
}
答案 0 :(得分:0)
如何在MainActivity类中使用startActivityForResult()。您可以覆盖onActivityResult()以启用/禁用图像。这只是一个建议。