0

我在我的偏好中有一个编辑框,用户可以在其中输入一个数字来增加一个计数器,但我不知道如何获取这个值并在我的主类中使用它。

在我的偏好中,我有;

        android:defaultValue="1"
        android:inputType="number"
        android:key="incrementBy"
        android:maxLength="3"
        android:summary="Set the incremental value of the counter"
        android:title="Increase Count by" />

我想要做的是,从此编辑框中获取用户输入并将其隐含到我的主类中的一个变量中。

4

1 回答 1

0

你必须得到你的SharedPreferences对象,并从中检索“incrementBy”的值

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(yourActivity);
String incrementBy= sharedPref.getString("incrementBy", "defaultValue");
于 2014-12-14T13:44:28.173 回答