2

我有一个应用程序,其中有 Tab Host。我的选项卡主机中肯定有四个选项卡,其中一个选项卡包含一些元素的列表。现在,当用户单击第三个选项卡的元素时,他应该切换到第一个选项卡,并且列表元素的数据会显示在那里。但是当用户最初尝试单击第一个选项卡而不从第三个选项卡的列表中选择任何元素时,我需要显示“请从列表中选择一个项目”的警报消息

我想知道如何做到这一点?

谢谢,大卫

4

3 回答 3

1

使用警报对话框

于 2011-01-11T08:10:55.213 回答
1
Toast.makeText(this,"Please select an item form the List",Toast.LENGTH_LONG).show();

在您的点击事件中使用它。

于 2011-01-11T07:45:59.163 回答
0

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

于 2011-01-11T09:55:47.180 回答