如何防止 Tabchange 发生
大家好,
我(Android Rooky)在 Android 中使用 TabActivity 开发 WineCellerManagement,并且遇到了问题:-)
添加新酒时,我向用户展示 TabHost 内的 Activity,其中包含用户可以在几个编辑文本中输入的一些参数,他们可以在其中写入酒名、年份等。当他们更改选项卡时,选项卡的内容会在 onpause 方法中保存到 SQLiteDB 中,并向用户显示一些其他参数,以便该酒在第二个选项卡中输入。
我希望用户至少输入葡萄酒的名称和年份,我的想法是在保存数据之前检查 onPause 方法。如果没有名称和年份,我希望选项卡不更改,而是向用户展示带有错误消息的祝酒词。 有人知道该怎么做吗?
Hy everybody
I (Android Rooky) work on a WineCellerManagement with a TabActivity in Android and i have encountered a problem :-)
On adding a new wine, i present the user a Activity inside a TabHost with some of the parameters the user can enter in a couples of edittext's in which they can write wine-name, year and so on. As they change the Tab, the content of the tab is saved into a SQLiteDB in the onpause method and the user is presented some other parameters for that wine to enter in the second tab.
I want the user to enter at least a name and a year for the wine and my idea was to check in the onPause method just before saving the data. If there is no name and no year, i want the tab NOT to change and present the user a toast with the error message instead.
Does somebody know how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您应该移动代码以将数据从 onPause() 事件保存到 TabHost 的 OnChangeListener 中。
通过这种方式,您可以验证字段并向用户显示一条消息,然后调用 setCurrentTab() 来阻止当前选项卡发生更改。
我不想验证 onPause() 中的数据,因为当有呼叫进入或任何其他将活动推回到堆栈中的事件时,可能会触发该数据。
Perhaps you should move the code to save the data out of the onPause() event and into a OnChangeListener for the TabHost.
This way you can validate the fields and display a message back to the user, then call setCurrentTab() to what was the current tab preventing the tab changing.
I wouldn't want to validate the data in the onPause() as this could be fired when a call comes in or any other event that pushes the activity back in the stack.