Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Develop for the SmartPhone Using Techniques You Already Know : Page 3

The form factor is new, but developing applications for these cutting-edge devices is mostly old hat. Armed with just a few additional principles and warnings, you can be making apps for SmartPhones long before the rest of the pack.


advertisement
Deployment Issues
The first time you try to deploy, especially on a slower machine, you may get an error that says, simply, 'Deployment Errors.' This happens because the emulator takes a long time to load the first time it's used, and Visual Studio times out while waiting for it. If you get this error, you'll just need to wait until the emulator is fully loaded and hit F5 to deploy again.

Once the application is loaded, enter a stock symbol such as MSFT, IBM, or AMZN to retrieve the latest stock price for that company. Navigating the emulator via the mouse is tedious. These shortcuts should save you a whole lot of mouse clicks:

F1—Left Soft Key
F2—Right Soft Key
Esc—Behaves like the cancel/back button
Del—Deletes characters when in text editing mode



The XML returned by the Web service contains a lot of data. Therefore I decided to add a ListView control to the form to allow these details to be viewed. You will need to resize/reposition the controls on the form including the ListView control to ensure they fit on one screen. You then need to alter the ListView columns collection by adding two columns, Symbol and Price (see Figure 5).

Figure 5. ListView Control Columns Collection: Add two columns, Symbol and Price.
The default value for the View property of the ListView control is "LargeIcon," change this to "Details." This enables the ListView to display its items in detail showing each value.

Hit F7 to switch to code view. Add the following statement to the top of the file:

Imports System.XML

Double click on an empty space on the form to add a form load event, and paste the following into the load event:

TextBox1.Focus()

Why give the TextBox1 control focus? There is an issue with the tab order for controls. The default way to set the tab order is by selecting the menu View->Tab Order, but this doesnt work. There is another option under View->SmartPhone Tab Order, but this doesnt work at times. When the application is running, the ListView control on the form receives focus first. Thus navigating to the TextBox control to enter stock symbols becomes impossible. Giving the TextBox1 control focus in the form load event, circumvents this problem.

You also need to also alter the Go button's click event. Replace the code with the following:

Label2.Text = "Getting Stock Quote..." Me.Refresh() Dim myService As StockWS.StockQuote = New StockWS.StockQuote Dim dsStocks As New DataSet Dim sXML As String = myService.GetQuote(TextBox1.Text) Dim xmlSR As System.IO.StringReader = New System.IO.StringReader(sXML) Dim xmlR As XmlTextReader = New XmlTextReader(xmlSR) dsStocks.ReadXml(xmlR) ListView1.Items.Clear() For Each dr As DataRow In dsStocks.Tables(0).Rows() Dim Stock As New ListViewItem Stock.Text = dr("Symbol").ToString Stock.SubItems.Add(dr("Last").ToString()) ListView1.Items.Add(Stock) Next Label2.Text = "" Me.Refresh() TextBox1.Focus()

This code first creates an instance of the stock quote Web service. The XML returned from the GetQuote service is stored in a local variable sXML. Next I create a StringReader, xmlSR, and pass it the XML via the sXML variable. The StringReader in turn is passed to the XMLTextReader. The ReadXML method of the dataset accepts the XMLTextReader as a parameter to populate the dataset. Next I loop through the dataset rows and pick the relevant values of Symbol and Last (which is the last price of the stock) and these are added to the ListView items collection.

Hit F5 to run the application. This Web service will look up multiple stock symbols simultaneously, so this time put two symbol values in the TextBox, separated by a space (such as "MSFT AMZN"). The ListView will display the last traded values for both Microsoft and Amazon stocks.

Why use a dataset? A dataset provides a great deal of flexibility and lets you manipulate data very easily. In addition, just like the ReadXML method, you could use the WriteXML method to persist the data to the device.

Distribution and Security
Another gotcha to be aware of in the development environment is the Build Cab File option on the Build menu. This does not work for SmartPhone application development. You must use CabWizSP.exe at the command line to create CAB files for a SmartPhone application

SmartPhone application CAB files may need to be signed before they can run on the device. Most operators provide their own certification for applications before they can be loaded onto devices supplied by them. For more information, see Security in Managed Code and the .cab Signing topic in the SDK Adaptation Kit for Mobile Operators (AMO).This is part of the SmartPhone SDK documentation.

Support for the .NET CF opens the SmartPhone world to .NET developers. However, it's got a lot of rough edges that need to be smoothed. The first mover advantage does come with pitfalls. There are various business applications such as field force automation, distribution, and customized end user applications that can be developed leveraging the strength of Web services and the rich features of the device. This might just be the device that gives a real boost to the growing mobile market. Why not be there first?



Sanjay Shetty is the CEO of Wireless Strategist & Consultants, a consultancy for mobility, design, architecture, and .NET migration. He is the Microsoft regional director in Mumbai, India. Reach him via e-mail at .
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date