Eventful.com has a rich set of categories that cover the breadth of events happening around the globe; from music to business events, varied types of events are available. There may be users who are interested only in concert events, while another group of users prefer sports events. Customization that suits the end user's taste is key to an app's success.
The following table shows all categories of events supported by the Eventful API:
Category ID |
Category name |
---|---|
music |
Concerts & Tour Dates |
conference |
Conferences & Tradeshows |
learning_education |
Education |
family_fun_kids |
Kids & Family |
festivals_parades |
Festivals |
movies_film |
Film |
food |
Food & Wine |
fundraisers |
Fundraising & charity |
art |
Art Galleries & Exhibits |
support |
Health & Wellness |
books |
Library & Books |
attractions |
Museums & Attractions |
community |
Neighborhood |
business |
Business & Networking |
singles_social |
Nightlife & Singles |
schools_alumni |
University & Alumni |
clubs_association |
Organizations & Meetups |
outdoors_recreation |
Outdoors & Recreation |
performing_arts |
Performing Arts |
animals |
Pets |
politics_activisim |
Politics & Activism |
sales |
Sales & Retail |
science |
Science |
religion_spirituality |
Religion & Spirituality |
sports |
Sports |
technology |
Technology |
other |
Other and Miscellaneous |
We extend the HelloEvents
example we saw previously, and use the Eventful category API to filter events:
HelloEvents-Categories
. MainPage.xaml
and MainPage.xaml.cs
files of the HelloEvents
example. However, on the home screen, change the text of the Show Events
button to List Categories
, as we will now be showing a list of event categories and then the actual events, based on the category selection. click
event method name to showCategories_Click
, as shown in the following XAML code for the new List Categories
button:<Button Content="List Categories" Height="72" HorizontalAlignment="Left" Margin="-4,270,0,0" Name="button1" VerticalAlignment="Top" Width="231" Click="showCategories_Click" />
Click
event, we will not be showing the Events Page as we did earlier; instead, we will create a new Windows Phone Portrait Page (CategoryPage.xaml
) and use that as the second screen.private void showCategories_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate( new Uri("/CategoryPage.xaml?latitude=" + latitudeText.Text + "&longitude=" + longitudeText.Text, UriKind.Relative) ); }
ProgressBar
and ListBox
control to your CategoryPage.xaml
file to make it look like the following screenshot: CategoryPage.xaml.cs
file, we add the variables similar to our HelloEvents
example, however, now we add two more List
variables of type string — one to hold the category ID and another to hold the category name.public partial class CategoryPage :PhoneApplicationPage { WebClient myWebClient; String apiKey = "xxxxxxxxxxx"; // Get your own key from //Eventful List<string> myCategoryId; List<string> myCategoryName; string latitude; string longitude;
MainPage.xaml.cs
file). However, we need these variables to pass to our third page — EventPage.xaml
. CategoryPage()
constructor, we initialize the following variables:myWebClient = new WebClient(); myCategoryName = new List<string>(); myCategoryId = new List<string>();
OnNavigatedTo
method, we store the latitude and longitude obtained from the MainPage (the MainPage.xaml.cs
file) and call the Eventful.com API to get a list of all categories.Protected override void
OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
latitude = NavigationContext.QueryString["latitude"];
longitude = NavigationContext.QueryString["longitude"];
// Load Event Categories from Eventful.com API
myWebClient.DownloadStringCompleted += new
DownloadStringCompletedEventHandler
(myWebClient_DownloadStringCompleted);
Uri uri = new Uri
("http://api.evdb.com/rest/categories/list?app_key="
+ apiKey);
myWebClient.DownloadStringAsync(uri);
// End of Eventful API call.
}
myWebClient_DownloadStringCompleted
method and change the name of the XML tags to be parsed, as well as some string replacement to enhance the display.private void myWebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { XElement xml = XElement.Parse(e.Result); loadingBar.IsIndeterminate = false; loadingBar.Visibility = Visibility.Collapsed; ; IEnumerable<XElement> elements = xml.Descendants("category"); foreach (XElement element in elements) { String categoryName = element.Element("name").Value.Replace ("&", "&"); String categoryId = element.Element("id").Value; myCategoryId.Add(categoryId); myCategoryName.Add(categoryName); } myCategoriesList.ItemsSource = myCategoryName; }
List
variables. We did this purposely, as the index of both of the list items will be same, so mapping the category name to category ID will be easier. As mentioned earlier, the Eventful.com API works well with the category ID and not category name, as the former is cleaner text. SelectionChanged
attribute of the ListBox
control to define the method that will be fired when the user selects any item from the ListBox. This is done on the XAML side in our CategoryPage.xaml
as:<ListBox Height="595" HorizontalAlignment="Left" Margin="2,6,0,0" Name="myCategoriesList" VerticalAlignment="Top" Width="448" SelectionChanged="showEvents">
showEvents
method is where the third page of the application is called, and the latitude/longitude pair along with the event category selected is passed as a query string to the third XAML page, which is EventPage.xaml.
private void showEvents(object sender,
SelectionChangedEventArgs e)
{
String selectedCategoryId =
myCategoryId[myCategoriesList.SelectedIndex];
NavigationService.Navigate(new
Uri("/EventPage.xaml?latitude=" + latitude + "&longitude=" +
longitude + "&categoryId=" + selectedCategoryId,
UriKind.Relative)
);
}
List<string>
can be accessed by index, we add the appropriate values to the category ID list and category name list (myCategoryId and myCategoryName)
and access it as we need. Alternatively we could have chosen to use a multi-dimensional array. EventPage.xaml.cs
remains mostly the same as before, except for the addition of the category ID in the Eventful.com API to fetch nearby events. Note, the API URL changes a bit too, as shown in the following lines of code:protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); string latitude = NavigationContext.QueryString["latitude"]; string longitude = NavigationContext.QueryString["longitude"]; stringcategoryId = NavigationContext.QueryString["categoryId"]; // Load Events from Eventful.com API myWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler (myWebClient_DownloadStringCompleted); Uri uri = new Uri("http://api.eventful.com/rest/events/search?category=" + categoryId + "&location=" + latitude + "," + longitude + "&app_key=" + apiKey + "&within=10"); myWebClient.DownloadStringAsync(uri); // End of Eventful API call. }
CategoryPage.xaml
as shown in the following screenshot: EventPage.xaml
with events for the selected category, as shown in the following screenshot:Observe how the back button works seamlessly; play around with the location and event categories to see different events worldwide.
You can find this example project in the code files for the book underChapter 4, titled HelloEvents-Categories
.
52.15.137.91