开发者

Howto prevent Tabchange to happen

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 som开发者_如何学编程e 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜