<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Library &#187; Tips</title>
	<atom:link href="http://www.ucosoft.com/tag/tips/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Thu, 22 Jul 2010 05:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Android View Add Listener Tips Sample</title>
		<link>http://www.ucosoft.com/add-listener-tips-android-view-2.html</link>
		<comments>http://www.ucosoft.com/add-listener-tips-android-view-2.html#comments</comments>
		<pubDate>Fri, 18 Dec 2009 03:29:40 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/uncategorized/add-listener-tips-android-view-2.html</guid>
		<description><![CDATA[In the development for the control to add Listener is a very common work, the easiest way to add Listener can be: 1 findViewById &#40;R.id.myButton&#41;. setOnClickListener &#40;new View.OnClickListener &#40;&#41; &#40;public void onClick &#40;View v&#41; &#40;/ / Do stuff&#41;&#41;&#41;; Add a Listener using the above method has a drawback is that if control is too large, [...]]]></description>
			<content:encoded><![CDATA[<p>  In the development for the control to add Listener is a very common work, the easiest way to add Listener can be: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  findViewById <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">myButton</span><span style="color: #009900;">&#41;</span>. <span style="color: #006633;">setOnClickListener</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span> <span style="color: #339933;">/</span> <span style="color: #000000; font-weight: bold;">Do</span> stuff<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>  Add a Listener using the above method has a drawback is that if control is too large, Listener will increase the number, so the following tips can be used to reduce the number of Listener: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> handler <span style="color: #339933;">=</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>v.<span style="color: #006633;">getId</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button01</span><span style="color: #339933;">:</span> <span style="color: #339933;">/</span> <span style="color: #339933;">/</span> doStuff <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button02</span><span style="color: #339933;">:</span> <span style="color: #339933;">/</span> <span style="color: #339933;">/</span> doStuff <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> findViewById <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">myButton</span><span style="color: #009900;">&#41;</span>. <span style="color: #006633;">setOnClickListener</span> <span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> findViewById <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">myOtherButton</span><span style="color: #009900;">&#41;</span>. <span style="color: #006633;">setOnClickListener</span> <span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>  The Android1.6 inside, add the Listener&#39;s work has become fairly simple (feeling more like doing web programming!), Concrete steps are as follows: </p>
<p>  1. First, the definition in the layout inside the Button and specify the response Listener </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;?</span> xml version <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #cc66cc;">1.0</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span> encoding <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;?&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>LinearLayout xmlns<span style="color: #339933;">:</span> android <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//schemas.android.com/apk/res/android&amp;quot; android: orientation = &amp;quot;vertical&amp;quot; android: layout_width = &amp;quot;fill_parent&amp;quot; android: layout_height = &amp;quot;fill_parent&amp;quot;&amp;gt; &amp;lt;TextView android:layout_width=&amp;quot;fill_parent&amp;quot; android:layout_height=&amp;quot;wrap_content&amp;quot; android:text=&amp;quot;@string/hello&amp;quot; /&amp;gt; &amp;lt;Button android: text = &amp;quot;Button01&amp;quot; android : id = &amp;quot;@ + id/Button01&amp;quot; android: layout_width = &amp;quot;wrap_content&amp;quot; android: layout_height = &amp;quot;wrap_content&amp;quot; android: onClick = &amp;quot;myClickHandler01&amp;quot; /&amp;gt; &amp;lt;Button android: text = &amp;quot;Button02&amp;quot; android: id = &amp;quot;@ + id / Button02 &amp;quot;android: layout_width =&amp;quot; wrap_content &amp;quot;android: layout_height =&amp;quot; wrap_content &amp;quot;android: onClick =&amp;quot; myClickHandler02 &amp;quot;/&amp;gt; &amp;lt;TextView android: layout_width =&amp;quot; fill_parent &amp;quot;android: layout_height =&amp;quot; wrap_content &amp;quot;android: text =&amp;quot; @ string / hello &amp;quot;/&amp;gt; &amp;lt;/ LinearLayout&amp;gt;</span></pre></td></tr></table></div>

<p>  These two lines of which the following are new features: </p>
<p>  android: onClick = &quot;myClickHandler01&quot; </p>
<p>  android: onClick = &quot;myClickHandler02&quot; </p>
</p>
<p>  2. In the event inside the definition of public methods myClickHandler01, and myClickHandler02 (Note that these two methods must have a View of the shape parameter). </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.ray.test</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestOnClickListener <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#40;</span>@ Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate <span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span> <span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> setContentView <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myClickHandler01 <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler01<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myClickHandler02 <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler02<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>  Of course, you can also use this wording: </p>
<p>  The two buttons set to the same Listener </p>
<p>  android: onClick = &quot;myClickHandler&quot; </p>
<p>  android: onClick = &quot;myClickHandler&quot; </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.ray.test</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestOnClickListener <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#40;</span>@ Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate <span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span> <span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> setContentView <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myClickHandler <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>target.<span style="color: #006633;">getId</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button01</span><span style="color: #339933;">:</span> setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler01<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button02</span> <span style="color: #339933;">:</span> setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler02<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>  Refer to the article: &quot;UI framework changes in Android 1.6&quot; (take over the wall) </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/add" title="add" rel="tag">add</a>, <a href="http://www.ucosoft.com/tag/android" title="android" rel="tag">android</a>, <a href="http://www.ucosoft.com/tag/listener" title="listener" rel="tag">listener</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.ucosoft.com/tag/view" title="view" rel="tag">view</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/add-listener-tips-android-view-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add a Listener Tips Android View Sample</title>
		<link>http://www.ucosoft.com/add-listener-tips-android-view.html</link>
		<comments>http://www.ucosoft.com/add-listener-tips-android-view.html#comments</comments>
		<pubDate>Sat, 17 Oct 2009 22:16:08 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/uncategorized/add-listener-tips-android-view.html</guid>
		<description><![CDATA[In the development for the control to add Listener is a very common work, the easiest way to add Listener can be: 1 findViewById &#40;R.id.myButton&#41;. setOnClickListener &#40;new View.OnClickListener &#40;&#41; &#40;public void onClick &#40;View v&#41; &#40;/ / Do stuff&#41;&#41;&#41;; Add a Listener using the above method has a drawback is that if control is too large, [...]]]></description>
			<content:encoded><![CDATA[<p>  In the development for the control to add Listener is a very common work, the easiest way to add Listener can be: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  findViewById <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">myButton</span><span style="color: #009900;">&#41;</span>. <span style="color: #006633;">setOnClickListener</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span> <span style="color: #339933;">/</span> <span style="color: #000000; font-weight: bold;">Do</span> stuff<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>  Add a Listener using the above method has a drawback is that if control is too large, Listener will increase the number, so the following tips can be used to reduce the number of Listener: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> handler <span style="color: #339933;">=</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>v.<span style="color: #006633;">getId</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button01</span><span style="color: #339933;">:</span> <span style="color: #339933;">/</span> <span style="color: #339933;">/</span> doStuff <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button02</span><span style="color: #339933;">:</span> <span style="color: #339933;">/</span> <span style="color: #339933;">/</span> doStuff <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> findViewById <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">myButton</span><span style="color: #009900;">&#41;</span>. <span style="color: #006633;">setOnClickListener</span> <span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> findViewById <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">myOtherButton</span><span style="color: #009900;">&#41;</span>. <span style="color: #006633;">setOnClickListener</span> <span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>  The Android1.6 inside, add the Listener&#39;s work has become fairly simple (feeling more like doing web programming!), Concrete steps are as follows: </p>
<p>  1. First, the definition in the layout inside the Button and specify the response Listener </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;?</span> xml version <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #cc66cc;">1.0</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span> encoding <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;?&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>LinearLayout xmlns<span style="color: #339933;">:</span> android <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//schemas.android.com/apk/res/android&amp;quot; android: orientation = &amp;quot;vertical&amp;quot; android: layout_width = &amp;quot;fill_parent&amp;quot; android: layout_height = &amp;quot;fill_parent&amp;quot;&amp;gt; &amp;lt;TextView android:layout_width=&amp;quot;fill_parent&amp;quot; android:layout_height=&amp;quot;wrap_content&amp;quot; android:text=&amp;quot;@string/hello&amp;quot; /&amp;gt; &amp;lt;Button android: text = &amp;quot;Button01&amp;quot; android : id = &amp;quot;@ + id/Button01&amp;quot; android: layout_width = &amp;quot;wrap_content&amp;quot; android: layout_height = &amp;quot;wrap_content&amp;quot; android: onClick = &amp;quot;myClickHandler01&amp;quot; /&amp;gt; &amp;lt;Button android: text = &amp;quot;Button02&amp;quot; android: id = &amp;quot;@ + id / Button02 &amp;quot;android: layout_width =&amp;quot; wrap_content &amp;quot;android: layout_height =&amp;quot; wrap_content &amp;quot;android: onClick =&amp;quot; myClickHandler02 &amp;quot;/&amp;gt; &amp;lt;TextView android: layout_width =&amp;quot; fill_parent &amp;quot;android: layout_height =&amp;quot; wrap_content &amp;quot;android: text =&amp;quot; @ string / hello &amp;quot;/&amp;gt; &amp;lt;/ LinearLayout&amp;gt;</span></pre></td></tr></table></div>

<p>  These two lines of which the following are new features: </p>
<p>  android: onClick = &quot;myClickHandler01&quot; </p>
<p>  android: onClick = &quot;myClickHandler02&quot; </p>
</p>
<p>  2. In the event inside the definition of public methods myClickHandler01, and myClickHandler02 (Note that these two methods must have a View of the shape parameter). </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.ray.test</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestOnClickListener <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#40;</span>@ Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate <span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span> <span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> setContentView <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myClickHandler01 <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler01<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myClickHandler02 <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler02<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>  Of course, you can also use this wording: </p>
<p>  The two buttons set to the same Listener </p>
<p>  android: onClick = &quot;myClickHandler&quot; </p>
<p>  android: onClick = &quot;myClickHandler&quot; </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.ray.test</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestOnClickListener <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#40;</span>@ Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate <span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span> <span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> setContentView <span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myClickHandler <span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>target.<span style="color: #006633;">getId</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button01</span><span style="color: #339933;">:</span> setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler01<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">case</span> R.<span style="color: #006633;">id</span>.<span style="color: #006633;">Button02</span> <span style="color: #339933;">:</span> setTitle <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>myClickHandler02<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>  Refer to the article: &quot;UI framework changes in Android 1.6&quot; (take over the wall) </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/add" title="add" rel="tag">add</a>, <a href="http://www.ucosoft.com/tag/android" title="android" rel="tag">android</a>, <a href="http://www.ucosoft.com/tag/listener" title="listener" rel="tag">listener</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.ucosoft.com/tag/view" title="view" rel="tag">view</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/add-listener-tips-android-view.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>30 Great Tips of CListCtrl Program(2)</title>
		<link>http://www.ucosoft.com/30-great-tips-of-clistctrl-program2.html</link>
		<comments>http://www.ucosoft.com/30-great-tips-of-clistctrl-program2.html#comments</comments>
		<pubDate>Tue, 03 Jun 2008 02:35:16 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/06/03/30-great-tips-of-clistctrl-program2.html</guid>
		<description><![CDATA[30 Great Tips of CListCtrl Program(1) 8. Get Item Infomation TCHAR szBuf[1024];LVITEM lvi;lvi.iItem = nItemIndex;lvi.iSubItem = 0;lvi.mask = LVIF_TEXT;lvi.pszText = szBuf;lvi.cchTextMax = 1024;m_list.GetItem(&#38;lvi); More infomation: Q173242: Use Masks to Set/Get Item States in CListCtrl 9. Get the header titile of CListCtrl LVCOLUMN lvcol;char&#160; str[256];int&#160;&#160; nColNum;CString&#160; strColumnName[MAX_COL];nColNum = 0;lvcol.mask = LVCF_TEXT;lvcol.pszText = str;lvcol.cchTextMax = 256;while(m_list.GetColumn(nColNum, &#38;lvcol)){&#160;&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>
<p><a href="http://www.ucosoft.com/2008/06/03/30-greate-tips-of-clistctrl-program1.html">30 Great Tips of CListCtrl Program(1)</a></p>
</li>
</ul>
<p><strong>8. Get Item Infomation</strong></p>
<p>TCHAR szBuf[1024];<br />LVITEM lvi;<br />lvi.iItem = nItemIndex;<br />lvi.iSubItem = 0;<br />lvi.mask = LVIF_TEXT;<br />lvi.pszText = szBuf;<br />lvi.cchTextMax = 1024;<br />m_list.GetItem(&amp;lvi);
<p>More infomation: <a href="http://support.microsoft.com/kb/173242/en-us" target="_blank">Q173242: Use Masks to Set/Get Item States in CListCtrl</a>
<p><strong>9. Get the header titile of CListCtrl</strong><br />
<blockquote>
<p>LVCOLUMN lvcol;<br />char&nbsp; str[256];<br />int&nbsp;&nbsp; nColNum;<br />CString&nbsp; strColumnName[MAX_COL];<br />nColNum = 0;<br />lvcol.mask = LVCF_TEXT;<br />lvcol.pszText = str;<br />lvcol.cchTextMax = 256;<br />while(m_list.GetColumn(nColNum, &amp;lvcol))<br />{<br />&nbsp;&nbsp;&nbsp; strColumnName[nColNum] = lvcol.pszText;<br />&nbsp;&nbsp;&nbsp; nColNum++;<br />}</p>
</blockquote>
<p><strong>10. Scoll the scollbar to ensure item visible</strong></p>
<p><span id="more-108"></span></p>
<p><strong></strong>&nbsp;</p>
<blockquote><p>m_list.EnsureVisible(i, FALSE);</p>
</blockquote>
<p><strong>11. Get the column count of CListCtrl</strong></p>
<blockquote><p>int nHeadNum = m_list.GetHeaderCtrl()-&gt;GetItemCount();</p>
</blockquote>
<p><strong>12. Delete all the columns</strong></p>
<p><strong>Method 1:</strong></p>
<blockquote><p>while ( m_list.DeleteColumn (0));</p>
</blockquote>
<p>Once you delete the first column, the next columns will move above.</p>
<p><strong>Method 2:</strong></p>
<blockquote><p>for (int i=nColumns-1; i&gt;=0; i&#8211;)
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_list.DeleteColumn (i);</p>
</blockquote>
<p><strong>13. Get the row and column index of the clicked item</strong>
<p><strong>Method 1:</strong><br />
<blockquote>
<p>void CTestDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)<br />{<br />&nbsp;&nbsp; DWORD dwPos = GetMessagePos();<br />&nbsp;&nbsp; CPoint point( LOWORD(dwPos), HIWORD(dwPos) );<br />&nbsp;&nbsp; m_list.ScreenToClient(&amp;point);<br />&nbsp;&nbsp; LVHITTESTINFO lvinfo;<br />&nbsp;&nbsp; lvinfo.pt = point;<br />&nbsp;&nbsp; lvinfo.flags = LVHT_ABOVE;<br />&nbsp;&nbsp; int nItem = m_list.SubItemHitTest(&amp;lvinfo);<br />&nbsp;&nbsp; if(nItem != -1)<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CString strtemp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strtemp.Format(&#8220;You clicked row %d column %d&#8221;, lvinfo.iItem, lvinfo.iSubItem);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AfxMessageBox(strtemp);<br />&nbsp;&nbsp; }<br />}</p>
</blockquote>
<p><strong>Method 2:</strong></p>
<blockquote><p>void CTestDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)<br />{<br />&nbsp;&nbsp; NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;<br />&nbsp;&nbsp; if(pNMListView-&gt;iItem != -1)<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CString strtemp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strtemp.Format(&#8220;You clicked row %d column %d&#8221;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pNMListView-&gt;iItem, pNMListView-&gt;iSubItem);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AfxMessageBox(strtemp);<br />&nbsp;&nbsp; }<br />}</p>
</blockquote>
<p>14. Check if you clicked on the checkbox</p>
<blockquote><p>void CTestDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)<br />{<br />&nbsp;&nbsp; DWORD dwPos = GetMessagePos();<br />&nbsp;&nbsp; CPoint point( LOWORD(dwPos), HIWORD(dwPos) );<br />&nbsp;&nbsp; m_list.ScreenToClient(&amp;point);<br />&nbsp;&nbsp; LVHITTESTINFO lvinfo;<br />&nbsp;&nbsp; lvinfo.pt = point;<br />&nbsp;&nbsp; lvinfo.flags = LVHT_ABOVE;<br />&nbsp;&nbsp; UINT nFlag;<br />&nbsp;&nbsp; int nItem = m_list.HitTest(point, &amp;nFlag);<br />&nbsp;&nbsp; if(nFlag == LVHT_ONITEMSTATEICON)<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AfxMessageBox(&#8220;clicked on the checkbox&#8221;);<br />&nbsp;&nbsp; }<br />&nbsp;&nbsp; *pResult = 0;<br />}</p>
</blockquote>
<p><strong>15. pop up menu when right mouse button clicked</strong></p>
<blockquote><p>void CTestDlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)<br />{<br />&nbsp;&nbsp;&nbsp; NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;<br />&nbsp;&nbsp;&nbsp; if(pNMListView-&gt;iItem != -1)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD dwPos = GetMessagePos();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CPoint point( LOWORD(dwPos), HIWORD(dwPos) );<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CMenu menu;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VERIFY( menu.LoadMenu( IDR_MENU1 ) );<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CMenu* popup = menu.GetSubMenu(0);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASSERT( popup != NULL );<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; popup-&gt;TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; *pResult = 0;<br />}</p>
</blockquote>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/30-great-tips-of-clistctrl-program2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>30 Great Tips of CListCtrl Program(1)</title>
		<link>http://www.ucosoft.com/30-greate-tips-of-clistctrl-program1.html</link>
		<comments>http://www.ucosoft.com/30-greate-tips-of-clistctrl-program1.html#comments</comments>
		<pubDate>Tue, 03 Jun 2008 01:21:22 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/06/03/30-greate-tips-of-clistctrl-program1.html</guid>
		<description><![CDATA[Without a special note,the listctrl has the default view style of report. 1. CListCtrl style &#160;&#160;&#160;&#160;&#160;&#160; LVS_ICON: for each item displayed great icon &#160;&#160;&#160;&#160;&#160;&#160; LVS_SMALLICON: for each item displayed on the icon &#160;&#160;&#160;&#160;&#160;&#160; LVS_LIST: a show with a small icon on the item &#160;&#160;&#160;&#160;&#160;&#160; LVS_REPORT: Show item details &#160;&#160;&#160;&#160;&#160;&#160; You can inspect the Windows Explorer, [...]]]></description>
			<content:encoded><![CDATA[<p>Without a special note,the listctrl has the default view style of report. </p>
<p><strong>1. </strong><a href="http://www.ucosoft.com/tag/clistctrl" target="_blank"><strong>CListCtrl</strong></a><strong> style</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVS_ICON: for each item displayed great icon</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVS_SMALLICON: for each item displayed on the icon </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVS_LIST: a show with a small icon on the item </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVS_REPORT: Show item details </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You can inspect the Windows Explorer, just like &#8220;View&#8221; tab with &#8220;icon, small icon, list details&#8221;</p>
<p><strong>2. </strong><a href="http://www.ucosoft.com/tag/clistctrl" target="_blank"><strong>CListctrl</strong></a><strong> style and expand style </strong></p>
<p>LONG lStyle; <br />lStyle = GetWindowLong (m_list.m_hWnd, GWL_STYLE); // Get the current window style <br />lStyle &amp;= ~ LVS_TYPEMASK; // Clear display <br />lStyle |= LVS_REPORT; // set style <br />SetWindowLong (m_list.m_hWnd, GWL_STYLE, lStyle); // set style <br />DWORD dwStyle = m_list.GetExtendedStyle (); <br />dwStyle |= LVS_EX_FULLROWSELECT; // highlight the selected full row<br />dwStyle |= LVS_EX_GRIDLINES; // grid lines (with the style of the report) <br />dwStyle |= LVS_EX_CHECKBOXES; // checkbox controls <br />m_list.SetExtendedStyle (dwStyle); // set expand style
<p>Note: Please check <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50lrflistviewstyles.asp" target="_blank">MSDN</a> for style details.</p>
<p><span id="more-107"></span></p>
<p><strong>3. Insert data</strong> </p>
<p>m_list.InsertColumn (0, &#8220;ID&#8221;, LVCFMT_LEFT, 40); // insert column <br />m_list.InsertColumn (1, &#8220;NAME&#8221;, LVCFMT_LEFT, 50); <br />int nRow = m_list.InsertItem (0, &#8220;11 &#8220;);// Row <br />m_list.SetItemText (nRow, 1, &#8220;jacky &#8220;);// set of data</p>
<p><strong>4. Always selected item <br /></strong>Check the style of Show selection always, or in the section 2&nbsp; above set LVS_SHOWSELALWAYS style.</p>
<p><strong>5. Check and uncheck a row</strong></p>
<p>int nIndex = 0; <br />// Check <br />m_list.SetItemState (nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); <br />// Uncheck <br />m_list.SetItemState (nIndex, 0, LVIS_SELECTED | LVIS_FOCUSED);
<p><strong>6. Get the checkbox status of all the rows</strong>
<p>m_list.SetExtendedStyle(LVS_EX_CHECKBOXES);<br />CString str;<br />for(int i=0; i&lt;nRowCount;i++) <br />{<br />&nbsp;&nbsp; if( m_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED || m_list.GetCheck(i))<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str.Format(_T(&#8220;checkbox checked in row %d&#8221;), i);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AfxMessageBox(str);<br />&nbsp;&nbsp; }<br />}
<p><strong>7. Get the selected row index</strong>
<p><strong>Method 1:</strong>
<p>CString str;<br />for(int i=0; i&lt;nRowCount;i++)<br />{<br />&nbsp;&nbsp;&nbsp; if( m_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED )<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str.Format(_T(&#8220;ROW %d selected.&#8221;), i);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AfxMessageBox(str);<br />&nbsp;&nbsp;&nbsp; }<br />}
<p><strong>Method 2:</strong></p>
<p>POSITION pos = m_list.GetFirstSelectedItemPosition();<br />if (pos == NULL)<br />TRACE0(&#8220;No items were selected!\n&#8221;);<br />else<br />{<br />&nbsp;&nbsp;&nbsp; while (pos)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int nItem = m_list.GetNextSelectedItem(pos);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRACE1(&#8220;Item %d was selected!\n&#8221;, nItem);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // you could do your own processing on nItem here<br />&nbsp;&nbsp;&nbsp; }<br />}  </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/30-greate-tips-of-clistctrl-program1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Simplest way to change the row height of CListCtrl</title>
		<link>http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html</link>
		<comments>http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html#comments</comments>
		<pubDate>Mon, 14 Jan 2008 01:41:38 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/01/14/the-simplest-way-to-change-the-row-height-of-clistctrl.html</guid>
		<description><![CDATA[In the post &#8220;How to change the row height of CListCtrl&#8220;, it gives 2 solution example how to change row height or CListCtrl. Hower, it is not the simplest way. The simplest way to change the row height in a CListCtrl is: Display an icon with the desired height. All other ways that I know [...]]]></description>
			<content:encoded><![CDATA[<p>In the post &#8220;<a href="http://www.ucosoft.com/2006/12/05/how-to-change-the-row-height-of-clistctrl.html">How to change the row height of CListCtrl</a>&#8220;, it gives 2 solution example how to change row height or CListCtrl. Hower, it is not the simplest way.</p>
<p>The <strong>simplest</strong> way to change the row height in a CListCtrl is:<br />
<blockquote>
<p>Display an icon with the desired height. </p>
</blockquote>
<p>All other ways that I know of require significant programming (such as <strong>owner draw</strong>, which is often too much work). </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution of fatal error RC1004: unexpected end of file found</title>
		<link>http://www.ucosoft.com/solution-of-fatal-error-rc1004-unexpected-end-of-file-found.html</link>
		<comments>http://www.ucosoft.com/solution-of-fatal-error-rc1004-unexpected-end-of-file-found.html#comments</comments>
		<pubDate>Tue, 06 Nov 2007 03:09:16 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/11/06/solution-of-fatal-error-rc1004-unexpected-end-of-file-found.html</guid>
		<description><![CDATA[After you modified your reource.h, you may got this error: fatal error RC1004: unexpected end of file found. It&#8217;s a bug of the resource compiler. The solution is adding a blank line or two to the end of the file&#160; and build again. Tags: compile, error, resource, Tips]]></description>
			<content:encoded><![CDATA[<p>After you modified your reource.h, you may got this error:</p>
<p>fatal error RC1004: unexpected end of file found.</p>
<p>It&#8217;s a bug of the resource compiler. </p>
<p>The solution is adding a blank line or two to the end of the file&nbsp; and build again.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/compile" title="compile" rel="tag">compile</a>, <a href="http://www.ucosoft.com/tag/error" title="error" rel="tag">error</a>, <a href="http://www.ucosoft.com/tag/resource" title="resource" rel="tag">resource</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/solution-of-fatal-error-rc1004-unexpected-end-of-file-found.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to launch an Application with Admin privileges in VISTA</title>
		<link>http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html</link>
		<comments>http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html#comments</comments>
		<pubDate>Fri, 09 Mar 2007 07:36:57 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/75.html</guid>
		<description><![CDATA[When you develop some admin utility, which will need the administrator privilege to configures some H/W connected ove LAN, etc. And you will found that the application is running propertyly in XP just by a double click of the mouse, where as in VISTA if you run it as Administrator then only running. So, how [...]]]></description>
			<content:encoded><![CDATA[<p>When you develop some admin utility, which will need the administrator privilege to configures some H/W connected ove LAN, etc. And you will found that the application is running propertyly in XP just by a double click of the mouse, where as in VISTA if you run it as Administrator then only running.</p>
<p>So, how to get the privileges to your utility through programatically at the time of setup?</p>
<p>Here is the solution provided by <em><u>David Lowndes</u></em>:</p>
<p>To achieving this privilege, you need to add a manifest to your application that specifies a requestedExecutiionLevel of &#8220;<strong>requireAdminstrator</strong>&#8221; &#8211; whick tells Vista that it needs to run elevated.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.ucosoft.com/tag/vista" title="Vista" rel="tag">Vista</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Get the Primary Domain name</title>
		<link>http://www.ucosoft.com/how-to-get-the-primary-domain-name.html</link>
		<comments>http://www.ucosoft.com/how-to-get-the-primary-domain-name.html#comments</comments>
		<pubDate>Wed, 03 Jan 2007 11:28:37 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/69.html</guid>
		<description><![CDATA[In gina, the system will list the domain name of the current system. How to get the primary domain name in your program? From the released the Windows2000 and NT source code, you can get the code of gina. It locate on \win2k\private\windows\gina\winlogon\usrpro.c. Here is the code: DWORD rc; PWSTR PrimaryDomain; rc = NetGetJoinInformation ( [...]]]></description>
			<content:encoded><![CDATA[<p><P><br />
In gina, the system will list the domain name of the current system. How to get the primary domain name in your program?</p>
<p>From the released the Windows2000 and NT source code, you can get the code of gina. It locate on <strong>\win2k\private\windows\gina\winlogon\usrpro.c</strong>.</p>
<p>Here is the code:</p>
<p><span id="more-69"></span><br />
<coolcode lang="cpp" linenum="no"><br />
DWORD rc;<br />
PWSTR PrimaryDomain;</p>
<p>rc = NetGetJoinInformation (<br />
     NULL,<br />
     &#038;PrimaryDomain,<br />
     &#038;Type<br />
     );</p>
<p>if (rc != ERROR_SUCCESS)<br />
{<br />
    PrimaryDomain = NULL;<br />
}<br />
else<br />
{<br />
    wprintf(TEXT(&#8220;PrimaryDomain : %s\n&#8221;),PrimaryDomain);<br />
}<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/network" title="network" rel="tag">network</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-get-the-primary-domain-name.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MessageBox support Ctrl+C to copy content</title>
		<link>http://www.ucosoft.com/65.html</link>
		<comments>http://www.ucosoft.com/65.html#comments</comments>
		<pubDate>Mon, 01 Jan 2007 08:26:36 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MessageBox]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/65.html</guid>
		<description><![CDATA[It&#8217;s a good trick. From windows 2000, when a MessageBox popped out, you can use Ctrl+C to copy the content of the MessageBox window to the clipboard. It is a very interesting trick, and it is very usrful to share the information easily. The condition is only that the MessageBox window was created by MessageBoxA/MessageBoxW [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a good trick. From windows 2000, when a MessageBox popped out, you can use Ctrl+C to copy the content of the MessageBox window to the clipboard. It is a very interesting trick, and it is very usrful to share the information easily.</p>
<p>The condition is only that the MessageBox window was created by MessageBoxA/MessageBoxW from the win32 api. Whether you call AfxMessageBox or CWnd::MessageBox in vc or MsgBox in vb, they finally call the ::MessageBoxA or ::MessageBoxW, so it also works.</p>
<p>Here is a example.</p>
<p>1. When some message box popped, press Ctrl+C to copy.</p>
<p><img id="image64" style="width: 282px; height: 139px" height="139" alt="msgbox1.PNG" src="http://www.ucosoft.com/wp-content/uploads/2007/01/msgbox1.PNG" width="282" /></p>
<p>2. Paste in notepad, and you will see&#8230;<br />
<span id="more-65"></span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Notepad<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
The text in the Untitled file has changed.<br />
Do you want to save the changes?<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Yes No Cancel<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/messagebox" title="MessageBox" rel="tag">MessageBox</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/65.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable &#8220;profile&#8221; in Visual C++ 6.0</title>
		<link>http://www.ucosoft.com/how-to-enable-profile-in-vc-6.html</link>
		<comments>http://www.ucosoft.com/how-to-enable-profile-in-vc-6.html#comments</comments>
		<pubDate>Thu, 28 Dec 2006 11:11:52 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/68.html</guid>
		<description><![CDATA[From MSDN: The profiler is an analysis tool that you can use to examine the run-time behavior of your programs. By using profiler information, you can determine which sections of your code are working efficiently. The profiler can produce information showing areas of code that are not being executed or that are taking a long [...]]]></description>
			<content:encoded><![CDATA[<p><P><br />
<I>From MSDN</I>:<br />
The profiler is an analysis tool that you can use to examine the run-time behavior of your programs. By using profiler information, you can determine which sections of your code are working efficiently. The profiler can produce information showing areas of code that are not being executed or that are taking a long time to execute.</p>
<p>But in Visual C++ 6.0, you often found that the <strong>profile</strong> menu item is grayed. How to enable it?</p>
<p>To enable profile in VC 6.0, you first need to set the correct link parameter, and rebuild all the project.</P><br />
<coolcode linenum="no"><br />
Project|Setting|Link<br />
Enable profiling<br />
</coolcode><br />
<P><br />
Wait a minute, do you find that the profile menu item is still grayed?<br />
OK. It&#8217;s because that you installed vc6 with one account but use it with another one. It&#8217;s mayby a bug of VC6.<br />
But how can you to correct it? It&#8217;s easy. Just modify the entry value in the registery<span id="more-68"></span>.<br />
<coolcode lang="cpp" linenum="no"><br />
[HKEY_CURRENT_USER\Software\Microsoft\Devstudio\6.0\General]<br />
&#8220;ProfilerInstalled&#8221;=dword:00000001<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/profile" title="profile" rel="tag">profile</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.ucosoft.com/tag/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-enable-profile-in-vc-6.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

