1 | <html xmlns:saxon="http://icl.com/saxon"> |
---|
2 | <head> |
---|
3 | <link rel="stylesheet" type="text/css" href="doc.css"/> |
---|
4 | <link rel="stylesheet" type="text/css" href=""/> |
---|
5 | <meta author="The MathWorks Ltd."/> |
---|
6 | <meta copyright="2011 The MathWorks Ltd."/> |
---|
7 | <title>onListSelection</title> |
---|
8 | </head> |
---|
9 | |
---|
10 | |
---|
11 | <body> |
---|
12 | <table class="header" width="100%" border="0" cellspacing="0" cellpadding="0"> |
---|
13 | <tr> |
---|
14 | <td bgcolor="#e4f0f8"><A href="User guide.html"><font face="Arial" bgcolor="#e4f0f8" size="+0" underline="0" color="#000000"><b>User guide</b></font></A></td> |
---|
15 | <td width="36" bgcolor="#e4f0f8"><A HREF="User guide8_3.html"><IMG SRC="Images/leftarrow.png" BORDER="0" ALT="previous page"/></A><A HREF="User guide8_5.html"><IMG SRC="Images/rightarrow.png" BORDER="0" ALT="next page"/></A></td> |
---|
16 | </tr> |
---|
17 | </table> |
---|
18 | |
---|
19 | |
---|
20 | <br clear="all"/> |
---|
21 | |
---|
22 | <h2>8.4: onListSelection <a href="User guide8.html"><img src="Images/uparrow.png" border="0" align="top" alt="Go back up one level"/></a></h2> |
---|
23 | |
---|
24 | <p>Finally, let's have a look at how one of the callbacks works: "onListSelection", the function |
---|
25 | that is called when an item is selected in the listbox. The other |
---|
26 | callbacks obey the same pattern.</p> |
---|
27 | <p>The basic rule of thumb is that a callback should not update any part of |
---|
28 | the user interface directly - it's job is to respond to user interaction by changing the "data" structure. |
---|
29 | In this example, each callback changes the underlying data structure |
---|
30 | then asks the interface to refresh. This might mean that things update in the |
---|
31 | interface that don't need to, but ensures the callbacks remain simple and that all |
---|
32 | interface update logic is in one place. Extending this to more granular interface updates |
---|
33 | is straightforward. See <a href="demoBrowserScalability.html">Scalability</a> for more details.</p> |
---|
34 | <p>For the listbox callback, the "src" argument is a handle to the |
---|
35 | listbox and we simply need to update the SelectedDemo field of "data" |
---|
36 | to reflect the new selection. We then ask the rest of the interface to |
---|
37 | update in response to the change. |
---|
38 | </p> |
---|
39 | <example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011"> |
---|
40 | <code class="COMMENT">% User selected a demo from the list - update "data" and refresh</code> |
---|
41 | data.SelectedDemo = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( src, <code class="STRING">'Value'</code> ); |
---|
42 | updateInterface(); |
---|
43 | redrawDemo();</font></pre> |
---|
44 | <p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/demoBrowser4.png"/></center></font></p> |
---|
45 | </example> |
---|
46 | <p><small>(Full source code for this application is available here: |
---|
47 | [ <a href="Examples/demoBrowser.m">view</a> |
---|
48 | | <a href="matlab: edit(fullfile(layoutRoot,'layoutHelp','Examples','demoBrowser.m'))">edit</a> |
---|
49 | | <a href="matlab: p=pwd();cd(fullfile(layoutRoot,'layoutHelp','Examples')); demoBrowser; cd(p)">run</a> ] |
---|
50 | )</small></p> |
---|
51 | |
---|
52 | |
---|
53 | <br clear="ALL"/> |
---|
54 | <table class="footer" width="100%" border="0" cellspacing="0" cellpadding="0"> |
---|
55 | <tr> |
---|
56 | <td width="18" height="15" bgcolor="#e4f0f8" align="left"><a href="User guide8_3.html"><img src="images/leftarrow.png" border="0" alt="previous page"/></a></td> |
---|
57 | <td width="40%" height="15" bgcolor="#e4f0f8" align="left"><a href="User guide8_3.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">updateInterface</font></a></td> |
---|
58 | <td width="20%" height="15" bgcolor="#e4f0f8" align="center"><a href="index.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">[Top]</font></a></td> |
---|
59 | <td width="40%" height="15" bgcolor="#e4f0f8" align="right"><a href="User guide8_5.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Running it</font></a></td> |
---|
60 | <td width="18" height="15" bgcolor="#e4f0f8" align="right"><a href="User guide8_5.html"><img src="images/rightarrow.png" border="0" alt="next page"/></a></td> |
---|
61 | </tr> |
---|
62 | </table> |
---|
63 | <font face="Arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">© 2011 The MathWorks Ltd</font> |
---|
64 | <TT>• </TT><a href="matlab: helpview([matlabroot,'/license.txt'])">Terms of Use</a> |
---|
65 | <TT>• </TT><a href="matlab: helpview([matlabroot,'/patents.txt'])">Patents</a> |
---|
66 | <TT>• </TT><a href="matlab: helpview([matlabroot,'/trademarks.txt'])">Trademarks</a> |
---|
67 | |
---|
68 | </body> |
---|
69 | </html> |
---|
70 | |
---|