Android - ImageButton 值/SharedPreference
如果你有时间的话,可以抽出一些时间来陪我吗?我真的需要一些帮助。
让我解释一下; 我正在开发一个 Android 应用程序。
有一个布局,它有 5 个 ImageButton 和一个 webview。当用户单击图像按钮时,毫无问题它会调用下面的网站..但我或多或少有 20 个网站。我想为用户添加一个选项..例如,用户将从首选项中选择一个网站。屏幕然后会自动更改图像按钮值之一(我的意思是图标及其 loadurl 函数)。
我创建了首选屏幕,我可以在其中看到我在 array.xml 中编写的网站,
但我完全无法将它们设置为图像按钮..
我开始使用我们的最后一条曲线..然后它就会完成。
我尝试使用此代码:
Data = getSharedPreferences(filename, 0);
SharedPreferences.Editor e = data.edit();
e.putString("website", websiteVariable);
e.commit();
但我不能。 请一步一步向我解释清楚。 我也不希望这个问题只发生在我身上,在互联网上没有这个问题的来源。我搜索并尝试了我能想到的一切超过 6 天,但一无所获。 太感谢了
If you have time , please can you take some time for me ? I really need some help.
Let me explain;
Im working on an android app.
There is a layout and it has 5 ImageButton and a webview. When the users click on a imagebutton, without problem it calls a website below..but more or less i have 20 web site.i want to add an option for users..for example the user will choose a web site from Prefs. screen then automatically one of imagebuttons values (i mean icon AND its loadurl function) will change.
I created Pref Screen and i can see my website in this which i wrote in array.xml
but totally im not able to set them to Imagebuttons..
im beggin u.its our last curve..then it ll finish.
Im tried to use this code :
Data = getSharedPreferences(filename, 0);
SharedPreferences.Editor e = data.edit();
e.putString("website", websiteVariable);
e.commit();
but i couldnt.
Please explain me step by step clearly.
also i dont want that only for me,on internet there is no source for this issue.im searching and trying everything what i can think more than 6 days but nothing.
Thank you so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,它的作用是允许您存储用户信息,例如游戏得分、统计数据和其他变量。
第一行获取引用或创建要写入数据的文件。
第二行允许您编辑文件以向其中写入新信息。
采用两个参数,第一个参数是稍后提取值的键,第二个参数是要放入文件中的值。
最后一行提交数据,以便将其保存到文件中。
您可以从文档此处获取更多信息
此外,您想提取数据只需进行
编辑:
因此,例如,如果用户选择某个图像,您可以使用一个键来引用每个图像,并稍后获取值来决定用户之前选择的图标。
Basically what this does is allows you to store user information such as scores for a game, stats, and other variables.
The first line gets reference or creates the file to write the data to.
The second line allows you to edit the file to write new information to it..
Takes two parameters the first one being the Key to pull the value you out later, and the second being the value you want to put into the file.
The last line commits the data so that it is saved to the file.
You can get more info from the docs here
Also if you want to pull the data out just do
EDIT:
So for example if the user selects a certain image you could use a key to refer to each image and get the value later to decided which icon the user picked before.