我在我的搜索引擎应用程序中有3个网页浏览量.当用户输入他的查询时,默认情况下他获得谷歌搜索结果,然后是底部的雅虎和询问按钮,点击其中任何一个,他从这些网站获得该查询的结果.现在我想为用户提供更改默认结果站点的权限.我创造了3个radiobuttons.一旦确认,说他选择雅虎,我怎么能把它设置为雅虎,直到下次他将其改为其他网站,
Ama*_*lam 13
从SharedPreferences访问数据:
SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE);
String webViewChoice = sharedPref.getString("userChoice","null");
Run Code Online (Sandbox Code Playgroud)
如果没有保存选项(在应用程序第一次运行的情况下),你将获得"null" webViewChoice.根据需要使用此条件
在SharedPreferences中保存数据:
SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE);
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putString("userChoice",usersChoice);
prefEditor.commit();
Run Code Online (Sandbox Code Playgroud)
我希望它有所帮助.
| 归档时间: |
|
| 查看次数: |
3214 次 |
| 最近记录: |