<?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>Все о разработке для Android</title>
	<atom:link href="http://dev.androidteam.ru/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.androidteam.ru</link>
	<description></description>
	<lastBuildDate>Sun, 12 Dec 2010 14:40:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Создаем ProgressBar из кода</title>
		<link>http://dev.androidteam.ru/snippets/progressbar/customize-progressbar-from-code</link>
		<comments>http://dev.androidteam.ru/snippets/progressbar/customize-progressbar-from-code#comments</comments>
		<pubDate>Sun, 12 Dec 2010 14:38:25 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[ProgressBar]]></category>
		<category><![CDATA[ClipDrawable]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[Drawable]]></category>
		<category><![CDATA[LayerDrawable]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=240</guid>
		<description><![CDATA[В создании кастомного ProgressBar нет ничего сложного при использовании xml. А вот с созданием его же через код, у некоторых появляются проблемы. Решил выложить пример создания ProgressBar. Как вы увидите дальше, в этом нет ничего сложного: public class ProgressBarFromCode extends Activity &#123; &#160; &#160; @Override &#160; &#160; public void onCreate&#40;Bundle savedInstanceState&#41; &#123; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.androidteam.ru/wp-content/uploads/2010/12/custom_progressbar_code.png" alt="" title="custom_progressbar_code" width="320" height="124" class="alignnone size-full wp-image-242" /><br />
В создании кастомного ProgressBar нет ничего сложного при использовании xml. А вот с созданием его же через код, у некоторых появляются проблемы. Решил выложить пример создания ProgressBar. Как вы увидите дальше, в этом нет ничего сложного:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProgressBarFromCode <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://developer.android.com/reference/android/app/Activity.html"><span style="color: #003399; font-weight: bold;">Activity</span></a> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/os/Bundle.html"><span style="color: #003399; font-weight: bold;">Bundle</span></a> savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <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><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/view/LayoutInflater.html"><span style="color: #003399; font-weight: bold;">LayoutInflater</span></a> inflater = getLayoutInflater<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/LinearLayout.html"><span style="color: #003399; font-weight: bold;">LinearLayout</span></a> content = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/LinearLayout.html"><span style="color: #003399; font-weight: bold;">LinearLayout</span></a><span style="color: #009900;">&#41;</span> inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span>, <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; setContentView<span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Создаем необходимые drawable с нужными нам цветами</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// в нашем случае цвет фона: #484848, цвет прогресса: #00B01B</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html"><span style="color: #003399; font-weight: bold;">Drawable</span></a> background = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html"><span style="color: #003399; font-weight: bold;">ColorDrawable</span></a><span style="color: #009900;">&#40;</span>0xFF484848<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html"><span style="color: #003399; font-weight: bold;">Drawable</span></a> progress = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html"><span style="color: #003399; font-weight: bold;">ColorDrawable</span></a><span style="color: #009900;">&#40;</span>0xFF00B01B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/graphics/drawable/ClipDrawable.html"><span style="color: #003399; font-weight: bold;">ClipDrawable</span></a> clipProgress = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/graphics/drawable/ClipDrawable.html"><span style="color: #003399; font-weight: bold;">ClipDrawable</span></a><span style="color: #009900;">&#40;</span>progress, <a href="http://developer.android.com/reference/android/view/Gravity.html"><span style="color: #003399; font-weight: bold;">Gravity</span></a>.<span style="color: #006633;">LEFT</span>, <a href="http://developer.android.com/reference/android/graphics/drawable/ClipDrawable.html"><span style="color: #003399; font-weight: bold;">ClipDrawable</span></a>.<span style="color: #006633;">HORIZONTAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Создаем слои, которые понимает ProgressBar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html"><span style="color: #003399; font-weight: bold;">LayerDrawable</span></a> layerlist = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html"><span style="color: #003399; font-weight: bold;">LayerDrawable</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html"><span style="color: #003399; font-weight: bold;">Drawable</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> background, clipProgress <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; layerlist.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, android.<span style="color: #006633;">R</span>.<span style="color: #006633;">id</span>.<span style="color: #006633;">background</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; layerlist.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, android.<span style="color: #006633;">R</span>.<span style="color: #006633;">id</span>.<span style="color: #006633;">progress</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Создаем новый прогресс бар с горизонтальным стилем и нашим фоном</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/ProgressBar.html"><span style="color: #003399; font-weight: bold;">ProgressBar</span></a> progressBar = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/widget/ProgressBar.html"><span style="color: #003399; font-weight: bold;">ProgressBar</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #006600; font-weight: bold;">null</span>, android.<span style="color: #006633;">R</span>.<span style="color: #006633;">attr</span>.<span style="color: #006633;">progressBarStyleHorizontal</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006633;">setLayoutParams</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html"><span style="color: #003399; font-weight: bold;">LinearLayout.<span style="color: #006633;">LayoutParams</span></span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html"><span style="color: #003399; font-weight: bold;">LinearLayout.<span style="color: #006633;">LayoutParams</span></span></a>.<span style="color: #006633;">FILL_PARENT</span>, <a href="http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html"><span style="color: #003399; font-weight: bold;">LinearLayout.<span style="color: #006633;">LayoutParams</span></span></a>.<span style="color: #006633;">WRAP_CONTENT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006633;">setProgressDrawable</span><span style="color: #009900;">&#40;</span>layerlist<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; progressBar.<span style="color: #006633;">setProgress</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">42</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; content.<span style="color: #006633;">addView</span><span style="color: #009900;">&#40;</span>progressBar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Исходный код: <a href="http://dl.dropbox.com/u/1134234/AndroidTeam/dev/examples/ProgressBarFromCode.zip">ProgressBarFromCode.zip</a></p>
<p><em>p.s. Этот пример, это скорее ответ на топик на хабре <a href="http://habrahabr.ru/sandbox/21482/">Анимация под Android, или спроси у Google:</a> &#034;В качестве упражнения повышенной сложности попробуйте в runtime (не через XML) создать ProgressBar в виде полоски, а не кругляшка.&#034;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/progressbar/customize-progressbar-from-code/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Как показать клавиатуру для EditText?</title>
		<link>http://dev.androidteam.ru/snippets/inputmethodmanager/show-softkeyboard-for-edittext</link>
		<comments>http://dev.androidteam.ru/snippets/inputmethodmanager/show-softkeyboard-for-edittext#comments</comments>
		<pubDate>Mon, 22 Nov 2010 14:00:41 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[InputMethodManager]]></category>
		<category><![CDATA[INPUT_METHOD_SERVICE]]></category>
		<category><![CDATA[showSoftInput]]></category>
		<category><![CDATA[SHOW_FORCED]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=215</guid>
		<description><![CDATA[1. Создал простую разметку с кнопкой и текстовым полем ввода &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;LinearLayout &#160; &#160; android:layout_width=&#34;fill_parent&#34; &#160; &#160; android:layout_height=&#34;fill_parent&#34; &#160; &#160; xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34; &#160; &#160; android:orientation=&#34;vertical&#34; &#160; &#160; android:padding=&#34;40dp&#34;&#62; &#160; &#160; &#60;Button &#160; &#160; &#160; &#160; android:layout_height=&#34;wrap_content&#34; &#160; &#160; &#160; &#160; android:id=&#34;@+id/btn&#34; &#160; &#160; &#160; &#160; android:text=&#34;Show&#34; &#160; &#160; &#160; &#160; android:layout_width=&#34;fill_parent&#34;&#62;&#60;/Button&#62; &#160; &#160; &#60;EditText [...]]]></description>
			<content:encoded><![CDATA[<h2>1. Создал простую разметку с кнопкой и текстовым полем ввода</h2>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:padding</span>=<span style="color: #ff0000;">&quot;40dp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/btn&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Show&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/Button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EditText</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/edittext&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/EditText<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h2>2. Собственно сам код:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> InputMethodManagerTest <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://developer.android.com/reference/android/app/Activity.html"><span style="color: #003399; font-weight: bold;">Activity</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/EditText.html"><span style="color: #003399; font-weight: bold;">EditText</span></a> edit<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/Button.html"><span style="color: #003399; font-weight: bold;">Button</span></a> btn<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a> imm<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/os/Bundle.html"><span style="color: #003399; font-weight: bold;">Bundle</span></a> savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <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><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">input_method_manager_test</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imm = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a><span style="color: #009900;">&#41;</span> getSystemService<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/content/Context.html"><span style="color: #003399; font-weight: bold;">Context</span></a>.<span style="color: #006633;">INPUT_METHOD_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; edit = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/EditText.html"><span style="color: #003399; font-weight: bold;">EditText</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">edittext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; btn = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/Button.html"><span style="color: #003399; font-weight: bold;">Button</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">btn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; btn.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imm.<span style="color: #006633;">showSoftInput</span><span style="color: #009900;">&#40;</span>edit, <a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a>.<span style="color: #006633;">SHOW_FORCED</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Это конечно все хорошо, но этот код не будет работать если вам нужно показать клавиатуру при запуске активити. </p>
<p>Небольшое отступление. Поведение стандартной клавиатуры отличается на разных устройствах. Это зависит от наличия в устройстве физической клавиатуры.<br />
 &#8211; eсли нет физической клавиатуры, то программная по умолчанию будет автоматически отображаться, если фокус при запуске попадет на EditText.<br />
 &#8211; если физическая клавиатура есть, то программная будет спрятана при запуске.</p>
<p>Если нам нужно всегда отображать программную клавиатуру при запуске, поможет вот такой код:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/util/logging/Handler.html"><span style="color: #003399; font-weight: bold;">Handler</span></a> mHandler = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/util/logging/Handler.html"><span style="color: #003399; font-weight: bold;">Handler</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://developer.android.com/reference/android/widget/EditText.html"><span style="color: #003399; font-weight: bold;">EditText</span></a> myEditText<span style="color: #339933;">;</span><br />
<br />
<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* прячем программную клавиатуру<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> hideInputMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a> imm = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a><span style="color: #009900;">&#41;</span> getSystemService<span style="color: #009900;">&#40;</span>INPUT_METHOD_SERVICE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>imm <span style="color: #339933;">!</span>= <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imm.<span style="color: #006633;">hideSoftInputFromWindow</span><span style="color: #009900;">&#40;</span>myEditText.<span style="color: #006633;">getWindowToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* показываем программную клавиатуру<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> showInputMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a> imm = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html"><span style="color: #003399; font-weight: bold;">InputMethodManager</span></a><span style="color: #009900;">&#41;</span> getSystemService<span style="color: #009900;">&#40;</span>INPUT_METHOD_SERVICE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>imm <span style="color: #339933;">!</span>= <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imm.<span style="color: #006633;">showSoftInput</span><span style="color: #009900;">&#40;</span>myEditText, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/Runnable.html"><span style="color: #003399; font-weight: bold;">Runnable</span></a> mShowInputMethodTask = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/Runnable.html"><span style="color: #003399; font-weight: bold;">Runnable</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; showInputMethodForQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
@Override<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onWindowFocusChanged<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">boolean</span> hasFocus<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onWindowFocusChanged</span><span style="color: #009900;">&#40;</span>hasFocus<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hasFocus<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// если окно в фокусе, то ждем еще немного и показываем клавиатуру</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mHandler.<span style="color: #006633;">postDelayed</span><span style="color: #009900;">&#40;</span>mShowInputMethodTask, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/inputmethodmanager/show-softkeyboard-for-edittext/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ListView: Танцующий текст</title>
		<link>http://dev.androidteam.ru/snippets/listview/listview-dancing-text</link>
		<comments>http://dev.androidteam.ru/snippets/listview/listview-dancing-text#comments</comments>
		<pubDate>Tue, 19 Oct 2010 10:34:31 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[ListView]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=227</guid>
		<description><![CDATA[Иногда случается, что при нажатии на элементы списка, некоторые из них сдвигаются на 1-2 пикселя. Возможные варианты решения: &#8211; если у текста выставлен параметр для высоты &#8211; wrap_content, попробуйте изменить на фиксированную высоту &#8211; если у текста выставлен параметр gravity=&#034;center*&#034;, попробуйте убрать его совсем, что бы проверить оно или нет. &#8211; в итоге, это оказалась [...]]]></description>
			<content:encoded><![CDATA[<p>Иногда случается, что при нажатии на элементы списка, некоторые из них сдвигаются на 1-2 пикселя. </p>
<p>Возможные варианты решения:<br />
 &#8211; если у текста выставлен параметр для высоты &#8211; wrap_content, попробуйте изменить на фиксированную высоту<br />
 &#8211; если у текста выставлен параметр gravity=&#034;center*&#034;, попробуйте убрать его совсем, что бы проверить оно или нет.<br />
 &#8211; в итоге, это оказалась проблема с разделителем списка. Самое простое решение было его просто отключить: <code class="codecolorer xml default"><span class="xml">android:divider=&quot;@null&quot;</span></code> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/listview/listview-dancing-text/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Создаем диалог с картинками</title>
		<link>http://dev.androidteam.ru/snippets/dialog/items-with-images-in-dialog</link>
		<comments>http://dev.androidteam.ru/snippets/dialog/items-with-images-in-dialog#comments</comments>
		<pubDate>Thu, 12 Aug 2010 15:52:01 +0000</pubDate>
		<dc:creator>Dima Yarmolchuk</dc:creator>
				<category><![CDATA[Dialog]]></category>
		<category><![CDATA[AlertDialog]]></category>
		<category><![CDATA[BaseAdapter]]></category>
		<category><![CDATA[Images]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=197</guid>
		<description><![CDATA[Причина написания поста стало то, что когда возникла идея создать такой диалог: В Интернете не было не одного примера или описание как такое сделать, а попадались только стандартные диалоги: Не обошлось без помощи хороших людей, мне помогли, и я решил, поведать миру как это делать, если вы еще не умеете. Начнём…… Нам понадобится адаптер который [...]]]></description>
			<content:encoded><![CDATA[<p>Причина написания поста стало то, что когда возникла идея создать такой диалог:<br />
<a href="http://dev.androidteam.ru/wp-content/uploads/2010/08/dialog-with-images-1.png"><img src="http://dev.androidteam.ru/wp-content/uploads/2010/08/dialog-with-images-1-150x150.png" alt="" title="dialog-with-images-1" width="150" height="150" class="alignnone size-thumbnail wp-image-203" /></a><br />
В Интернете не было не одного примера или описание как такое сделать, а попадались только стандартные диалоги:<br />
<a href="http://dev.androidteam.ru/wp-content/uploads/2010/08/dialog-with-images-2.png"><img src="http://dev.androidteam.ru/wp-content/uploads/2010/08/dialog-with-images-2-300x128.png" alt="" title="dialog-with-images-2" width="300" height="128" class="alignnone size-medium wp-image-208" /></a><br />
Не обошлось без помощи хороших людей, мне помогли, и я решил, поведать миру как это делать, если вы еще не умеете. Начнём……<br />
Нам понадобится адаптер который мы возьмем из исходников андроида</p>
<p><span id="more-197"></span></p>
<p><strong>Aдаптер, который был взят с исходникв андроида.</strong></p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* Adapter showing the types of items that can be added to a {@link Workspace}.<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AddAdapter <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://developer.android.com/reference/android/widget/BaseAdapter.html"><span style="color: #003399; font-weight: bold;">BaseAdapter</span></a> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://developer.android.com/reference/android/view/LayoutInflater.html"><span style="color: #003399; font-weight: bold;">LayoutInflater</span></a> mInflater<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>ListItem<span style="color: #339933;">&gt;</span> mItems = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>ListItem<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> ITEM_SHORTCUT = <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> ITEM_APPWIDGET = <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> ITEM_LIVE_FOLDER = <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> ITEM_WALLPAPER = <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Specific item in our list.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ListItem <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/CharSequence.html"><span style="color: #003399; font-weight: bold;">CharSequence</span></a> text<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html"><span style="color: #003399; font-weight: bold;">Drawable</span></a> image<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> actionTag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ListItem<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/content/res/Resources.html"><span style="color: #003399; font-weight: bold;">Resources</span></a> res, <span style="color: #006600; font-weight: bold;">int</span> textResourceId, <span style="color: #006600; font-weight: bold;">int</span> imageResourceId, <span style="color: #006600; font-weight: bold;">int</span> actionTag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text = res.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>textResourceId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>imageResourceId <span style="color: #339933;">!</span>= -<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = res.<span style="color: #006633;">getDrawable</span><span style="color: #009900;">&#40;</span>imageResourceId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; &nbsp;font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = <span style="color: #006600; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">actionTag</span> = actionTag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> AddAdapter<span style="color: #009900;">&#40;</span>dialog launcher<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; mInflater = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/LayoutInflater.html"><span style="color: #003399; font-weight: bold;">LayoutInflater</span></a><span style="color: #009900;">&#41;</span> launcher.<span style="color: #006633;">getSystemService</span><span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/content/Context.html"><span style="color: #003399; font-weight: bold;">Context</span></a>.<span style="color: #006633;">LAYOUT_INFLATER_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create default actions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/content/res/Resources.html"><span style="color: #003399; font-weight: bold;">Resources</span></a> res = launcher.<span style="color: #006633;">getResources</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_shortcuts</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_shortcut</span>, ITEM_SHORTCUT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_widgets</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_appwidget</span>, ITEM_APPWIDGET<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_live_folders</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_folder_live</span>, ITEM_LIVE_FOLDER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_wallpapers</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_gallery</span>, ITEM_WALLPAPER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> getView<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> position, <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> convertView, <a href="http://developer.android.com/reference/android/view/ViewGroup.html"><span style="color: #003399; font-weight: bold;">ViewGroup</span></a> parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ListItem item = <span style="color: #009900;">&#40;</span>ListItem<span style="color: #009900;">&#41;</span> getItem<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>convertView == <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convertView = mInflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">add_list_item</span>, parent, <span style="color: #006600; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a> textView = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a><span style="color: #009900;">&#41;</span> convertView<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>item.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">setCompoundDrawablesWithIntrinsicBounds</span><span style="color: #009900;">&#40;</span>item.<span style="color: #006633;">image</span>, <span style="color: #006600; font-weight: bold;">null</span>, <span style="color: #006600; font-weight: bold;">null</span>, <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> convertView<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">int</span> getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> mItems.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="color: #003399; font-weight: bold;">Object</span></a> getItem<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> mItems.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">long</span> getItemId<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> position<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<h2>1. Для хранения данных мы будем использовать <strong>ArrayList<ListItem></strong>, где  <strong>ListItem</strong>:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ListItem <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/CharSequence.html"><span style="color: #003399; font-weight: bold;">CharSequence</span></a> text<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html"><span style="color: #003399; font-weight: bold;">Drawable</span></a> image<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> actionTag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ListItem<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/content/res/Resources.html"><span style="color: #003399; font-weight: bold;">Resources</span></a> res, <span style="color: #006600; font-weight: bold;">int</span> textResourceId, <span style="color: #006600; font-weight: bold;">int</span> imageResourceId, <span style="color: #006600; font-weight: bold;">int</span> actionTag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text = res.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>textResourceId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>imageResourceId <span style="color: #339933;">!</span>= -<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = res.<span style="color: #006633;">getDrawable</span><span style="color: #009900;">&#40;</span>imageResourceId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; &nbsp;font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = <span style="color: #006600; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">actionTag</span> = actionTag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<h2>2. Заполнение того самого ListItem делается так:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>ListItem<span style="color: #339933;">&gt;</span> mItems = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>ListItem<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_shortcuts</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_shortcut</span>, ITEM_SHORTCUT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_widgets</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_appwidget</span>, ITEM_APPWIDGET<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_live_folders</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_folder_live</span>, ITEM_LIVE_FOLDER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ListItem<span style="color: #009900;">&#40;</span>res, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">group_wallpapers</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_launcher_gallery</span>, ITEM_WALLPAPER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h2>3. Не забываем про add_list_item.xml:</h2>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:minHeight</span>=<span style="color: #ff0000;">&quot;?android:attr/listPreferredItemHeight&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:textAppearance</span>=<span style="color: #ff0000;">&quot;?android:attr/textAppearanceLargeInverse&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:gravity</span>=<span style="color: #ff0000;">&quot;center_vertical&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:drawablePadding</span>=<span style="color: #ff0000;">&quot;14dip&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:paddingLeft</span>=<span style="color: #ff0000;">&quot;15dip&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:paddingRight</span>=<span style="color: #ff0000;">&quot;15dip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<h2>4. И использование нашего диалога:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; AddAdapter mAdapter = <span style="color: #000000; font-weight: bold;">new</span> AddAdapter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/CharSequence.html"><span style="color: #003399; font-weight: bold;">CharSequence</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> items = <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Shortcuts&quot;</span>, <span style="color: #0000ff;">&quot;Widgets&quot;</span>, <span style="color: #0000ff;">&quot;Folders&quot;</span>, <span style="color: #0000ff;">&quot;Wallpapers&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/app/AlertDialog.Builder.html"><span style="color: #003399; font-weight: bold;">AlertDialog.<span style="color: #006633;">Builder</span></span></a> alt_bld = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/app/AlertDialog.Builder.html"><span style="color: #003399; font-weight: bold;">AlertDialog.<span style="color: #006633;">Builder</span></span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; alt_bld.<span style="color: #006633;">setIcon</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">ic_tray_collapse</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; alt_bld.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">menu_item_add_item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; alt_bld.<span style="color: #006633;">setAdapter</span><span style="color: #009900;">&#40;</span>mAdapter, <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html"><span style="color: #003399; font-weight: bold;">DialogInterface.<span style="color: #006633;">OnClickListener</span></span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/content/DialogInterface.html"><span style="color: #003399; font-weight: bold;">DialogInterface</span></a> dialog, <span style="color: #006600; font-weight: bold;">int</span> item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a>.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>getApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, items<span style="color: #009900;">&#91;</span>item<span style="color: #009900;">&#93;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a>.<span style="color: #006633;">LENGTH_SHORT</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/app/AlertDialog.html"><span style="color: #003399; font-weight: bold;">AlertDialog</span></a> alert = alt_bld.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; alert.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p><strong>Исходный код: <a href="http://dl.dropbox.com/u/1134234/AndroidTeam/dev/examples/DialogImage.zip">DialogImage.zip</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/dialog/items-with-images-in-dialog/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Создаем список содержащий NumberPicker</title>
		<link>http://dev.androidteam.ru/snippets/listview/listview-with-text-and-numberpicker</link>
		<comments>http://dev.androidteam.ru/snippets/listview/listview-with-text-and-numberpicker#comments</comments>
		<pubDate>Tue, 10 Aug 2010 12:59:11 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[ListView]]></category>
		<category><![CDATA[EfficientAdapter]]></category>
		<category><![CDATA[NumberPicker]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=174</guid>
		<description><![CDATA[В этом примере мы создали список, в котором, каждый элемент состоит из текста и NumberPicker. В качестве адаптера для списка был использован EfficientAdapter из примеров API Demos: list14.java. NumberPicker был полностью перенесен из исходников андроида. Замечание: не используйте рефлексию для доступа к NumberPicker. Лучше перенести полностью все исходники из андроид в свой проект. 1. Разметка [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.androidteam.ru/wp-content/uploads/2010/08/listview_numberpicker.png"><img src="http://dev.androidteam.ru/wp-content/uploads/2010/08/listview_numberpicker-150x150.png" alt="Listview NumberPicker" title="listview_numberpicker" width="150" height="150" class="alignleft size-thumbnail wp-image-175" /></a>В этом примере мы создали список, в котором, каждый элемент состоит из текста и NumberPicker. В качестве адаптера для списка был использован EfficientAdapter из примеров API Demos: list14.java.</p>
<p>NumberPicker был полностью перенесен из исходников андроида.</p>
<p><em><strong>Замечание:</strong> не используйте рефлексию для доступа к NumberPicker. Лучше перенести полностью все исходники из андроид в свой проект.</em></p>
<p><span id="more-174"></span></p>
<div style="clear:both";></div>
<h2>1. Разметка основного окна:</h2>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ListView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/list&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/ListView<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h2>2. Создаем разметку для элемента списка:</h2>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:paddingLeft</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:paddingRight</span>=<span style="color: #ff0000;">&quot;5dp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/text&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_weight</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:textSize</span>=<span style="color: #ff0000;">&quot;16sp&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:gravity</span>=<span style="color: #ff0000;">&quot;center_vertical&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ru.androidteam.listviewnumberpicker.NumberPicker</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/nPicker&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h2>3. Для хранения данных списка будем использовать <code class="codecolorer android default"><span class="android">ArrayList<span style="color: #339933;">&lt;</span>ItemData<span style="color: #339933;">&gt;</span></span></code>, где ItemData:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ItemData <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> text<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> number<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ItemData<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> text, <span style="color: #006600; font-weight: bold;">int</span> number<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">text</span> = text<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">number</span> = number<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<h2>4. Адаптер, как уже писал выше, основан на примере из API Demos:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> EfficientAdapter <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://developer.android.com/reference/android/widget/BaseAdapter.html"><span style="color: #003399; font-weight: bold;">BaseAdapter</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://developer.android.com/reference/android/view/LayoutInflater.html"><span style="color: #003399; font-weight: bold;">LayoutInflater</span></a> mInflater<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ArrayList<span style="color: #339933;">&lt;</span>ItemData<span style="color: #339933;">&gt;</span> mItems<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> EfficientAdapter<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/content/Context.html"><span style="color: #003399; font-weight: bold;">Context</span></a> context, ArrayList<span style="color: #339933;">&lt;</span>ItemData<span style="color: #339933;">&gt;</span> items<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Cache the LayoutInflate to avoid asking for a new one each time.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mInflater = <a href="http://developer.android.com/reference/android/view/LayoutInflater.html"><span style="color: #003399; font-weight: bold;">LayoutInflater</span></a>.<span style="color: #006633;">from</span><span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mItems = items<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">int</span> getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> mItems.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ItemData getItem<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> mItems.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">long</span> getItemId<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> position<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> getView<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> position, <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> convertView, <a href="http://developer.android.com/reference/android/view/ViewGroup.html"><span style="color: #003399; font-weight: bold;">ViewGroup</span></a> parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ViewHolder holder<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>convertView == <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convertView = mInflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">list_item</span>, <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder = <span style="color: #000000; font-weight: bold;">new</span> ViewHolder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder.<span style="color: #006633;">text</span> = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a><span style="color: #009900;">&#41;</span> convertView.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder.<span style="color: #006633;">nPicker</span> = <span style="color: #009900;">&#40;</span>NumberPicker<span style="color: #009900;">&#41;</span> convertView.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">nPicker</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder.<span style="color: #006633;">nPicker</span>.<span style="color: #006633;">setOnChangeListener</span><span style="color: #009900;">&#40;</span>numberPickerOnChangedListener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convertView.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>holder<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; &nbsp;font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder = <span style="color: #009900;">&#40;</span>ViewHolder<span style="color: #009900;">&#41;</span> convertView.<span style="color: #006633;">getTag</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// сохраняем каждый раз позицию текущего элемента в tag view объект</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// мы будем использовать его для обновления данных при изменении NubmberPicker</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder.<span style="color: #006633;">nPicker</span>.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ItemData data = mItems.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder.<span style="color: #006633;">text</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>data.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; holder.<span style="color: #006633;">nPicker</span>.<span style="color: #006633;">setCurrent</span><span style="color: #009900;">&#40;</span>data.<span style="color: #006633;">number</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> convertView<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> ViewHolder <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a> text<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NumberPicker nPicker<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<h2>5. Обработчик изменений NumberPicker.</h2>
<p>Так как у нас все данные находятся в массиве, то при изменении числа в NumberPicker нам нужно обновлять его и у нас. Сделать это можно через NumberPicker.OnChangedListener:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NumberPicker.<span style="color: #006633;">OnChangedListener</span> numberPickerOnChangedListener = <span style="color: #000000; font-weight: bold;">new</span> NumberPicker.<span style="color: #006633;">OnChangedListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onChanged<span style="color: #009900;">&#40;</span>NumberPicker picker, <span style="color: #006600; font-weight: bold;">int</span> oldVal, <span style="color: #006600; font-weight: bold;">int</span> newVal<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// получаем позицию из tag объекта NumberPicker</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> position = <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/Integer.html"><span style="color: #003399; font-weight: bold;">Integer</span></a><span style="color: #009900;">&#41;</span> picker.<span style="color: #006633;">getTag</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ItemData item = adapter.<span style="color: #006633;">getItem</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; item.<span style="color: #006633;">number</span> = newVal<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<h2>6. И последнее, создаем несколько тестовых данных, инициализируем адаптер и устанавливаем его в ListView:</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@Override<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/os/Bundle.html"><span style="color: #003399; font-weight: bold;">Bundle</span></a> savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <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><br />
&nbsp; &nbsp; 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><br />
<br />
&nbsp; &nbsp; ArrayList<span style="color: #339933;">&lt;</span>ItemData<span style="color: #339933;">&gt;</span> items = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>ItemData<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ItemData<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Первый&quot;</span>, <span style="color: #cc66cc;">44</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ItemData<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Второй&quot;</span>, <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ItemData<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Дерево&quot;</span>, <span style="color: #cc66cc;">26</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ItemData<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Еще что то&quot;</span>, <span style="color: #cc66cc;">56</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ItemData<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Стол&quot;</span>, <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ItemData<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Кружка&quot;</span>, <span style="color: #cc66cc;">33</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; list = <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/javax/swing/text/html/ListView.html"><span style="color: #003399; font-weight: bold;">ListView</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; adapter = <span style="color: #000000; font-weight: bold;">new</span> EfficientAdapter<span style="color: #009900;">&#40;</span>getApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, items<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; list.<span style="color: #006633;">setAdapter</span><span style="color: #009900;">&#40;</span>adapter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p><strong>Исходный код: <a href="http://dl.dropbox.com/u/1134234/AndroidTeam/dev/examples/ListView_NumberPicker.zip">ListView_NumberPicker.zip</a></strong></p>
<p><em><strong>Замечание:</strong> Возможно при импорте проекта в Eclipse нужно будет сделать Project -> Clean&#8230;, выбрать проект (поставить галочку слева) и нажать OK</em></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/listview/listview-with-text-and-numberpicker/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Как установить контекстное меню для ListView?</title>
		<link>http://dev.androidteam.ru/snippets/listview/listview-contextmenu</link>
		<comments>http://dev.androidteam.ru/snippets/listview/listview-contextmenu#comments</comments>
		<pubDate>Tue, 10 Aug 2010 10:28:21 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[ListView]]></category>
		<category><![CDATA[AdapterContextMenuInfo]]></category>
		<category><![CDATA[onCreateContextMenu]]></category>
		<category><![CDATA[setOnCreateContextMenuListener]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=150</guid>
		<description><![CDATA[Устанавливаем обработчик для контекстного меню, на текущий в Активити: list.setOnCreateContextMenuListener&#40;this&#41;; И дальше реализовываем обработку. &#160; &#160;@Override &#160; &#160; public void onCreateContextMenu&#40;ContextMenu menu, View v, ContextMenuInfo menuInfo&#41; &#123; &#160; &#160; &#160; &#160; AdapterContextMenuInfo aMenuInfo = &#40;AdapterContextMenuInfo&#41; menuInfo; &#160; &#160; &#160; &#160; // Получаем позицию элемента в списке &#160; &#160; &#160; &#160; int position = aMenuInfo.position; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Устанавливаем обработчик для контекстного меню, на текущий в Активити:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">list.<span style="color: #006633;">setOnCreateContextMenuListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>И дальше реализовываем обработку.</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;@Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onCreateContextMenu<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/ContextMenu.html"><span style="color: #003399; font-weight: bold;">ContextMenu</span></a> menu, <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> v, ContextMenuInfo menuInfo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; AdapterContextMenuInfo aMenuInfo = <span style="color: #009900;">&#40;</span>AdapterContextMenuInfo<span style="color: #009900;">&#41;</span> menuInfo<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Получаем позицию элемента в списке</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> position = aMenuInfo.<span style="color: #006633;">position</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Получаем данные элемента списка, тип данных здесь вы должны указать свой!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> AdapterData data = adapter.<span style="color: #006633;">getItem</span><span style="color: #009900;">&#40;</span>aMenuInfo.<span style="color: #006633;">position</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; menu.<span style="color: #006633;">setHeaderTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Заголовок&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; menu.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Первый элемент&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setOnMenuItemClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnMenuItemClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">boolean</span> onMenuItemClick<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/awt/MenuItem.html"><span style="color: #003399; font-weight: bold;">MenuItem</span></a> item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// дествия по клику меню</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/listview/listview-contextmenu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Как сделать обтекание картинки текстом у TextView (api8)?</title>
		<link>http://dev.androidteam.ru/snippets/textview/leadingmarginspan2</link>
		<comments>http://dev.androidteam.ru/snippets/textview/leadingmarginspan2#comments</comments>
		<pubDate>Tue, 03 Aug 2010 19:11:48 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[TextView]]></category>
		<category><![CDATA[android.text.style]]></category>
		<category><![CDATA[LeadingMarginSpan2]]></category>
		<category><![CDATA[SpannableString]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=129</guid>
		<description><![CDATA[Этот пример поможет вам, использовать место под картинкой, которое обычно остается пустым. Начиная с api 8 (Android 2.2) появился новый интерфейс LeadingMarginSpan2, который позволяет создавать отступ текста для N первых строк. На картинке создан отступ в 50 пикселей для 3 первых строк. Итак, приступим. 1. Разметка. &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;RelativeLayout &#160; &#160; xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Этот пример поможет вам, использовать место под картинкой, которое обычно остается пустым. </p>
<p>Начиная с api 8 (Android 2.2) появился новый интерфейс LeadingMarginSpan2, который позволяет создавать отступ текста для N первых строк. На картинке создан отступ в 50 пикселей для 3 первых строк.</p>
<p><img src="http://dev.androidteam.ru/wp-content/uploads/2010/08/leading_margin_span2.png" alt="Отступ для 3 первых строк" title="leading_margin_span2" width="320" height="209" class="alignnone size-full wp-image-132" /></p>
<p>Итак, приступим.</p>
<p><span id="more-129"></span></p>
<h2>1. Разметка.</h2>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RelativeLayout</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;match_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:padding</span>=<span style="color: #ff0000;">&quot;5dp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:textSize</span>=<span style="color: #ff0000;">&quot;18.0sp&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/message_view&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;match_parent&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/text&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ImageView</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:src</span>=<span style="color: #ff0000;">&quot;@drawable/icon&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/icon&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RelativeLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h2>2. Реализация класса LeadingMarginSpan2. </h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> MyLeadingMarginSpan2 <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://developer.android.com/reference/android/text/style/LeadingMarginSpan.LeadingMarginSpan2.html"><span style="color: #003399; font-weight: bold;">LeadingMarginSpan.<span style="color: #006633;">LeadingMarginSpan2</span></span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #006600; font-weight: bold;">int</span> margin<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #006600; font-weight: bold;">int</span> lines<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; MyLeadingMarginSpan2<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> lines, <span style="color: #006600; font-weight: bold;">int</span> margin<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">margin</span> = margin<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lines</span> = lines<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Возвращает значение, на которе должен быть добавлен отступ */</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">int</span> getLeadingMargin<span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">boolean</span> first<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>first<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Данный отступ будет применен к количеству строк<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* возвращаемых getLeadingMarginLineCount()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> margin<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; &nbsp;font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Отступ для всех остальных строк</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> drawLeadingMargin<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/graphics/Canvas.html"><span style="color: #003399; font-weight: bold;">Canvas</span></a> c, <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/awt/Paint.html"><span style="color: #003399; font-weight: bold;">Paint</span></a> p, <span style="color: #006600; font-weight: bold;">int</span> x, <span style="color: #006600; font-weight: bold;">int</span> dir, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> top, <span style="color: #006600; font-weight: bold;">int</span> baseline, <span style="color: #006600; font-weight: bold;">int</span> bottom, <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/CharSequence.html"><span style="color: #003399; font-weight: bold;">CharSequence</span></a> text, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> start, <span style="color: #006600; font-weight: bold;">int</span> end, <span style="color: #006600; font-weight: bold;">boolean</span> first, <a href="http://developer.android.com/reference/android/text/Layout.html"><span style="color: #003399; font-weight: bold;">Layout</span></a> layout<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp;* Возвращает количество строк, к которым должен быть <br />
&nbsp; &nbsp; &nbsp;* применен отступ возвращаемый методом getLeadingMargin(true)<br />
&nbsp; &nbsp; &nbsp;* Замечание:<br />
&nbsp; &nbsp; &nbsp;* Отступ применяется только к N строкам первого параграфа.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">int</span> getLeadingMarginLineCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> lines<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<h2>3. В OnCreate, создаем объект SpannableString и применяем новый стиль.</h2>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/os/Bundle.html"><span style="color: #003399; font-weight: bold;">Bundle</span></a> savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <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><br />
&nbsp; &nbsp; &nbsp; &nbsp; 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><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> text = getString<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Получаем иконку и ее ширину</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html"><span style="color: #003399; font-weight: bold;">Drawable</span></a> dIcon = getResources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDrawable</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">icon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> leftMargin = dIcon.<span style="color: #006633;">getIntrinsicWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> + <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Устанавливаем иконку в R.id.icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/javax/swing/text/html/ImageView.html"><span style="color: #003399; font-weight: bold;">ImageView</span></a> icon = <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/javax/swing/text/html/ImageView.html"><span style="color: #003399; font-weight: bold;">ImageView</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">icon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; icon.<span style="color: #006633;">setBackgroundDrawable</span><span style="color: #009900;">&#40;</span>dIcon<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/text/SpannableString.html"><span style="color: #003399; font-weight: bold;">SpannableString</span></a> ss = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/text/SpannableString.html"><span style="color: #003399; font-weight: bold;">SpannableString</span></a><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Выставляем отступ для первых трех строк абазца</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ss.<span style="color: #006633;">setSpan</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MyLeadingMarginSpan2<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, leftMargin<span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span>, ss.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a> messageView = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">message_view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; messageView.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>ss<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p><strong>Исходный код: <a href="http://dl.dropbox.com/u/1134234/AndroidTeam/dev/examples/MyLeadingMarginSpan2.zip">MyLeadingMarginSpan2.zip</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/textview/leadingmarginspan2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Как получить список всех детей View объекта?</title>
		<link>http://dev.androidteam.ru/snippets/get-view-childs-list</link>
		<comments>http://dev.androidteam.ru/snippets/get-view-childs-list#comments</comments>
		<pubDate>Mon, 02 Aug 2010 13:21:14 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[Примеры кода]]></category>
		<category><![CDATA[Childs]]></category>
		<category><![CDATA[instanceof]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[View]]></category>
		<category><![CDATA[ViewGroup]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=101</guid>
		<description><![CDATA[Следующий пример кода, поможет вам получить список всех детей любого View объекта. &#160; &#160; private ArrayList&#60;View&#62; getViewChildsList&#40;Object o&#41; &#123; &#160; &#160; &#160; &#160; ArrayList&#60;View&#62; views = new ArrayList&#60;View&#62;&#40;&#41;; &#160; &#160; &#160; &#160; if &#40;o instanceof ViewGroup&#41; &#123; &#160; &#160; &#160; &#160; &#160; &#160; ViewGroup vg = &#40;ViewGroup&#41; o; &#160; &#160; &#160; &#160; &#160; &#160; views.add&#40;vg&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Следующий пример кода, поможет вам получить список всех детей любого View объекта.</p>
<p><span id="more-101"></span></p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ArrayList<span style="color: #339933;">&lt;</span>View<span style="color: #339933;">&gt;</span> getViewChildsList<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="color: #003399; font-weight: bold;">Object</span></a> o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ArrayList<span style="color: #339933;">&lt;</span>View<span style="color: #339933;">&gt;</span> views = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>View<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #000000; font-weight: bold;">instanceof</span> <a href="http://developer.android.com/reference/android/view/ViewGroup.html"><span style="color: #003399; font-weight: bold;">ViewGroup</span></a><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/view/ViewGroup.html"><span style="color: #003399; font-weight: bold;">ViewGroup</span></a> vg = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/ViewGroup.html"><span style="color: #003399; font-weight: bold;">ViewGroup</span></a><span style="color: #009900;">&#41;</span> o<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; views.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>vg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-weight: bold;">int</span> count = vg.<span style="color: #006633;">getChildCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">int</span> i = <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> count<span style="color: #339933;">;</span> i++<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; views.<span style="color: #006633;">addAll</span><span style="color: #009900;">&#40;</span>getViewChildsList<span style="color: #009900;">&#40;</span>vg.<span style="color: #006633;">getChildAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; &nbsp;font-weight: bold;">else</span> <span style="color: #000000; &nbsp;font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #000000; font-weight: bold;">instanceof</span> <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; views.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a><span style="color: #009900;">&#41;</span> o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> views<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>Рассмотрим пример, на основе текущей активити:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/os/Bundle.html"><span style="color: #003399; font-weight: bold;">Bundle</span></a> savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <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><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Получаем View объект разметки для Activity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> layout = getLayoutInflater<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span>, <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; setContentView<span style="color: #009900;">&#40;</span>layout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Получаем список всех детей у layout</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ArrayList<span style="color: #339933;">&lt;</span>View<span style="color: #339933;">&gt;</span> allViews = getViewChildsList<span style="color: #009900;">&#40;</span>layout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Выводим количество найденных View</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/System.html"><span style="color: #003399; font-weight: bold;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;View count: &quot;</span> + allViews.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Выводим все объекты используя метод v.toString()</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; &nbsp;font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> v : allViews<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/System.html"><span style="color: #003399; font-weight: bold;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>v.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/snippets/get-view-childs-list/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Создание оповещений с помощью Toast</title>
		<link>http://dev.androidteam.ru/guide/topics/ui/notifiers/toast</link>
		<comments>http://dev.androidteam.ru/guide/topics/ui/notifiers/toast#comments</comments>
		<pubDate>Sun, 01 Aug 2010 16:30:26 +0000</pubDate>
		<dc:creator>Vladimir Baryshnikov</dc:creator>
				<category><![CDATA[Оповещение]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Toast]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://dev.androidteam.ru/?p=5</guid>
		<description><![CDATA[Toast &#8211; это простое оповещение пользователя. При отображении занимает минимальное количество места, необходимого для отображения сообщения. С тостами нельзя взаимодействовать. При отображении используется эффект появления и затухания. Скриншот ниже показывает пример оповещения пользователя из приложения Будильник. Как только время будильника установлено, отображается toast, который показывает через какое время включится будильник. Toast может быть создан и [...]]]></description>
			<content:encoded><![CDATA[<p>Toast &#8211; это простое оповещение пользователя. При отображении занимает минимальное количество места, необходимого для отображения сообщения. С тостами нельзя взаимодействовать. При отображении используется эффект появления и затухания.</p>
<p>Скриншот ниже показывает пример оповещения пользователя из приложения Будильник. Как только время будильника установлено, отображается toast, который показывает через какое время включится будильник.</p>
<p><img src="http://dev.androidteam.ru/wp-content/uploads/2010/08/alarm-toast.png" alt="" title="alarm-toast" width="320" height="157" class="alignnone size-full wp-image-43" /></p>
<p><span id="more-5"></span></p>
<p>Toast может быть создан и показан как из <strong>Activity</strong>, так и из <strong>Service</strong>. Если вы создадите toast оповещение из сервиса, то оно отобразится перед Activity находящейся в данный момент в фокусе.</p>
<p>Если необходима реакция от пользователя, то лучше использовать панель уведомлений (Status Bar Notification).</p>
<h2>Основы</h2>
<p>Необходимо создать Toast объект с помощью одного из <strong>makeText()</strong> методов. Этот метод получает три параметра: контекст приложения (Context), сообщение и время отображения. В качестве результата возвращается  Toast объект. Для отображения которого, нужно вызвать метод <strong>show()</strong>, как показано в пример ниже:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.android.com/reference/android/content/Context.html"><span style="color: #003399; font-weight: bold;">Context</span></a> context = getApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/java/lang/CharSequence.html"><span style="color: #003399; font-weight: bold;">CharSequence</span></a> text = <span style="color: #0000ff;">&quot;Hello toast!&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-weight: bold;">int</span> duration = <a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a>.<span style="color: #006633;">LENGTH_SHORT</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a> toast = <a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a>.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>context, text, duration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
toast.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Этот пример подходит для большинства случаев. Вам редко понадобится использовать что нибудь другое. Однако, возможно вы захотите задать другое положение на экране или изменить внешний вид. Далее будут рассмотрены оба случая.</p>
<p>Можно так же отобразить тост без создания дополнительной переменной, вызвав метод <strong>show()</strong>, как показано в примере ниже:﻿﻿</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a>.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span>context, text, duration<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h2>Позиционирование Toast</h2>
<p>По умолчанию тост оповещение появляется в низу экрана, центрированное по горизонтали. Вы можете изменить позицию с помощью метода <strong>setGravity(int, int, int)</strong>. Метод принимает три параметра: Gravity константа, сдвиг по x, сдвиг по y.<br />
Например, вы решили что хотите показывать оповещение в верхнем левом углу, тогда нужно установить  gravity следующим образом:</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">toast.<span style="color: #006633;">setGravity</span><span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/Gravity.html"><span style="color: #003399; font-weight: bold;">Gravity</span></a>.<span style="color: #006633;">TOP</span>|Gravity.<span style="color: #006633;">LEFT</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Если нужно сдвинуть немного в право, увеличьте второй параметр, если влево &#8211; третий параметр.</p>
<h2>Модифицирование Toast</h2>
<p><img alt="" src="http://developer.android.com/images/custom_toast.png" title="Custom Toast" class="alignright" width="200" height="300" /><br />
Если отображение в виде простого сообщения не достаточно, вы можете использовать любую разметку, какую только захотите. Для этого нужно создать xml разметку в папке res\layout или с помощью кода прямо в приложении, и передать объект View методу setView(View).</p>
<p>Например, создадим разметку показанную на картинке, с помощью следующей xml разметки (сохраним файл под именем toast_layout.xml):</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/toast_layout_root&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:padding</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:background</span>=<span style="color: #ff0000;">&quot;#DAAA&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ImageView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/image&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">android:layout_marginRight</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/text&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:textColor</span>=<span style="color: #ff0000;">&quot;#FFF&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Заметим, что идентификатор элемента LinearLayout &#8211; &#034;toast_layout&#034;. Далее мы будем использовать этот идентификатор для создания объекта View из xml разметки, как показано ниже:﻿﻿</p>
<div class="codecolorer-container android default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="android codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.android.com/reference/android/view/LayoutInflater.html"><span style="color: #003399; font-weight: bold;">LayoutInflater</span></a> inflater = getLayoutInflater<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://developer.android.com/reference/android/view/View.html"><span style="color: #003399; font-weight: bold;">View</span></a> layout = inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">toast_layout</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/ViewGroup.html"><span style="color: #003399; font-weight: bold;">ViewGroup</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">toast_layout_root</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/javax/swing/text/html/ImageView.html"><span style="color: #003399; font-weight: bold;">ImageView</span></a> image = <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/1%2E5%2E0/docs/api/javax/swing/text/html/ImageView.html"><span style="color: #003399; font-weight: bold;">ImageView</span></a><span style="color: #009900;">&#41;</span> layout.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
image.<span style="color: #006633;">setImageResource</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">drawable</span>.<span style="color: #006633;">android</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a> text = <span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/TextView.html"><span style="color: #003399; font-weight: bold;">TextView</span></a><span style="color: #009900;">&#41;</span> layout.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
text.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello! This is a custom toast!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a> toast = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a><span style="color: #009900;">&#40;</span>getApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
toast.<span style="color: #006633;">setGravity</span><span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/view/Gravity.html"><span style="color: #003399; font-weight: bold;">Gravity</span></a>.<span style="color: #006633;">CENTER_VERTICAL</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
toast.<span style="color: #006633;">setDuration</span><span style="color: #009900;">&#40;</span><a href="http://developer.android.com/reference/android/widget/Toast.html"><span style="color: #003399; font-weight: bold;">Toast</span></a>.<span style="color: #006633;">LENGTH_LONG</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
toast.<span style="color: #006633;">setView</span><span style="color: #009900;">&#40;</span>layout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
toast.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Первое, мы получили LayoutInflater через метод getLayoutInflater() (так же можно использовать getSystemService()), и затем создали объект View из Xml разметки с помощью метода <strong>inflate(int, ViewGroup)</strong>. Первый параметр &#8211; это идентификатор ресурса, второй &#8211; корневой View объект, к которому мы хотим подсоединить текущий. Вы можете использовать созданный объект, для поиска в нем других объектов, например, ImageView для установки картинки и TextView для текста сообщения. И наконец, создаем новый Toast с помощью конструктора <strong>Toast(Context)</strong> и проставляем свойства, такие как гравитация и время отображения. Затем вызываем метод <strong>setView(View)</strong> и передаем ему объект-разметку. Теперь можно отобразить ваш тост, вызвав метод <strong>show()</strong>.</p>
<blockquote><p><strong>Замечание:</strong> Не нужно использовать публичный конструктор для создания Toast, если вы не собираетесь устанавливать свою разметку через метод <strong>setView(View)</strong>.<br />
Для всех остальных случаев достаточно использовать метод <strong>makeText(Context, int, int)</strong>.</p></blockquote>
<p><em>Перевод статьи: <a href="http://developer.android.com/guide/topics/ui/notifiers/toasts.html">Creating Toast Notifications</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.androidteam.ru/guide/topics/ui/notifiers/toast/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

