开发者

Displaying Alert Message Box on click event

I have an application where I have Tab Host. I have certainly four tabs in my Tab Host and one of my tab contains a list of some elements. Now When a user click on the element of the third Tab he is supposed to switched to the first tab and the data of the list element gets displayed there. But when开发者_Go百科 the user initially tries to click on the first Tab without selecting any element from the list of third tab, I need to display the Alert Message that "Please select an item form the List"

I wonder how to do that particularly?

Thanks, david


use AlertDialog.


Toast.makeText(this,"Please select an item form the List",Toast.LENGTH_LONG).show();

use it on your click event.


You can use any of the above, but I feel its the logic that you're more interested in.

You might be having four different activities for each tab.

Create on more class, which will serve as your Bean class, which holds all the data to transfer information between classes.

  • Call this class as PrefBean.
  • Make all its variables static (as of now you'll be using only one to know whether user has selected any list item, and if yes, which one). This way, the variables will be globally available to all of your activities.
  • Have an integer in PrefBean which depicts whether something is selected or not in your third tab.

The logic goes as this:

  • Initially, your integer in PrefBean will hold something less than zero (say -1). This will show that nothing is selected as of then.
  • When user clicks in the first tab, your first activity will be invoked and it should check the value of that integer in PrefBean, display an error message to the user. If the value is negative, means nothing is selected, if its positive, it will give you the position of the row selected. Load anything depending on the row position selected
  • When user clicks on any row in your third tab's list activity, set your PrefBean integer == the row position selected.

I hope you got the logic

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜