【问题标题】:Implementing a button that only shows up when a checkbox is checked in another activity (android)实现一个仅在另一个活动中选中复选框时显示的按钮(android)
【发布时间】:2013-12-06 10:08:57
【问题描述】:

需要有关如何实现仅在选中另一个活动中的某个复选框时才显示的按钮的帮助/提示。

例如: 在一个选择你自己的冒险故事应用中

编辑片段活动:如果您希望片段中的按钮随机选择一个选项,您可以选中一个复选框。

如何使按钮仅在选中此复选框时弹出?

这是我创建的 randomChoice 方法。只需要上面的提示。提前致谢。

    /**
 * This method takes in an Array list of choices. It returns a random story
 * fragment ID of a possible fragment that the current story fragment might
 * go to.
 * 
 * Example: If there is a fragment that has choices a,b,c, each of them
 * leading to different fragments through toGoToStoryFragmentID. This method
 * will then choose one of these possible choices at random and return that
 * fragment ID.
 * 
 * @param Choices
 *            An array list of choice objects containing all the possible
 *            choices of the fragment.
 * @return The next story fragment ID that the randomChoice chose out of the
 *         possible choices.
 */
public static int randomChoice(ArrayList<Choice> choices) {
int ChoiceListSize = choices.size();
Random rand = new Random();
int randomIndexNumber = rand.nextInt(ChoiceListSize);
Choice chosenChoice = choices.get(randomIndexNumber);
return chosenChoice.getStoryFragmentID();

【问题讨论】:

  • 在哪里可以找到解决方案,如果您能分享答案,那将非常有用

标签: android android-intent checkbox android-activity android-fragmentactivity


【解决方案1】:

您可以使用SharedPreferences,或者如果您的活动通过Intent 直接连接,您也可以传递一个布尔值,无论复选框是否被选中。

试试这些链接:

【讨论】:

    猜你喜欢
    • 2016-12-20
    • 2016-12-20
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2021-08-23
    相关资源
    最近更新 更多