<?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>阳春面的学习摘录 &#187; Android</title>
	<atom:link href="http://chenyc.info/category/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://chenyc.info</link>
	<description>人生是一个不断折腾的过程，生命不息，折腾不止</description>
	<lastBuildDate>Mon, 06 Feb 2012 12:48:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Android NDK介绍及JNI调用</title>
		<link>http://chenyc.info/2012/01/android-ndk-and-jni/</link>
		<comments>http://chenyc.info/2012/01/android-ndk-and-jni/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 03:36:32 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[jni]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=798</guid>
		<description><![CDATA[Android NDK是用来编译能在手机ARM平台上运行的，通过C/C++编写的LIB库。 注：理论上不只在ARM平台，以后应该也能在Intel x86平台上运行的。 JNI调用，是为了使java能够调用C/C++所编写的程序的一种机制。 Android NDK和JNI调用结合，就能够使Android程序，调用原生底层用C/C++实现的功能。 1.NDK开发环境配置 在Windows下开发需要安装Cygwin，安装时除了默认选择项外，还要选中gcc和make. 在Linux下，如Ubuntu，通过apt-get 安装gcc和make即可。 然后下载NDK，解压到特定的目录（如：D:\Android） 由于awt兼容性的问题，需要将D:\Android\android-ndk-r7\prebuilt\windows\bin中的awt.exe改为awt_.exe. 同时把D:\Android\android-ndk-r7加入到系统的PATH中，方便使用， 打开Cygwin，cd到/cygdrive/d/Android/android-ndk-r7/samples/hello-jni/jni目录，输入ndk-build，测试环境是否正常 出现以上显示的内容，即表示环境配置正常。 注：/cygdrive/d/即表示windows中的D盘。 2.开发Android测试程序 新建一个Android项目hello,包名com.hello 把自动生成的HelloActivity中修改为以下内容 public class HelloActivity extends Activity { private static final String TAG = &#34;Hello&#34;; static { System.loadLibrary(&#34;hello&#34;); } private native String &#8230; <a href="http://chenyc.info/2012/01/android-ndk-and-jni/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Android NDK是用来编译能在手机ARM平台上运行的，通过C/C++编写的LIB库。</p>
<p>注：理论上不只在ARM平台，以后应该也能在Intel x86平台上运行的。</p>
<p>JNI调用，是为了使java能够调用C/C++所编写的程序的一种机制。</p>
<p>Android NDK和JNI调用结合，就能够使Android程序，调用原生底层用C/C++实现的功能。</p>
<p><strong>1.NDK</strong><strong>开发环境配置</strong></p>
<p>在Windows下开发需要安装<a href="http://www.cygwin.com/">Cygwin</a>，安装时除了默认选择项外，还要选中gcc和make.</p>
<p><a href="/blog/wp-content/uploads/2012/01/img1.jpg"><img class="alignnone size-full wp-image-257" title="img1" src="/blog/wp-content/uploads/2012/01/img1.jpg" alt="" width="439" height="320" /></a></p>
<p>在Linux下，如Ubuntu，通过apt-get 安装gcc和make即可。</p>
<p>然后<a href="http://developer.android.com/sdk/ndk/index.html">下载NDK</a>，解压到特定的目录（如：D:\Android）</p>
<p>由于awt兼容性的问题，需要将D:\Android\android-ndk-r7\prebuilt\windows\bin中的awt.exe改为awt_.exe.</p>
<p>同时把D:\Android\android-ndk-r7加入到系统的PATH中，方便使用，</p>
<p>打开Cygwin，cd到/cygdrive/d/Android/android-ndk-r7/samples/hello-jni/jni目录，输入ndk-build，测试环境是否正常</p>
<p><a href="/blog/wp-content/uploads/2012/01/img2.jpg"><img class="alignnone size-full wp-image-258" title="img2" src="/blog/wp-content/uploads/2012/01/img2.jpg" alt="" width="453" height="253" /></a></p>
<p>出现以上显示的内容，即表示环境配置正常。</p>
<p>注：/cygdrive/d/即表示windows中的D盘。</p>
<p><strong>2.</strong><strong>开发</strong><strong>Android</strong><strong>测试程序</strong></p>
<p>新建一个Android项目hello,包名com.hello</p>
<p>把自动生成的HelloActivity中修改为以下内容</p>
<pre>
public class HelloActivity extends Activity {

	private static final String TAG = &quot;Hello&quot;;

	static {
		System.loadLibrary(&quot;hello&quot;);
	}

	private native String printJNI();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Log.d(TAG, printJNI());
	}
}
</pre>
<p>通过System.loadLibrary(“hello”)加载C编写的LIB，并定义native方法printJNI，最后调用printJNI()方法测试。</p>
<p><strong>3.开发C语言程序，并通过NDK编译</strong></p>
<p>在新建在helo项目的根目录下新建jni目录，如D:\MyWorkSpace3\hello</p>
<p>打开终端，转到D:\MyWorkSpace3\hello\，执行</p>
<pre>javah -classpath bin/classes -d jni com.hello.HelloActivity</pre>
<p>执行成功后，会在jni目录下生成com_hello_HelloActivity.h头文件；<br />
接着在jni目录下新建一个C文件com_hello_HelloActivity.c，编写如下代码：</p>
<pre>
#include &quot;com_hello_HelloActivity.h&quot;
#define LOG_TAG &quot;JNITest&quot;
#undef LOG
JNIEXPORT jstring JNICALL Java_com_hello_HelloActivity_printJNI
(JNIEnv * env, jobject obj)
{
return (*env)-&gt;NewStringUTF(env, (char *)&quot;JNITest Native String&quot;);
}
</pre>
<p>再在jni目录下新建一个Android.mk文件，用于配置编译的文件及选项</p>
<pre>
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := hello
LOCAL_SRC_FILES := com_hello_HelloActivity.c

include $(BUILD_SHARED_LIBRARY)
</pre>
<p>LOCAL_PATH指编译文件的目录，$(call my-dir)指向当前目录<br />
LOCAL_MODULE指定编译生成的lib名字<br />
LOCAL_SRC_FILES指需要编辑的源文件，可自动多个文件，换行时用\分隔</p>
<p>完成后打开Cygwin,cd到项目的jni目录下，<br />
比如/cygdrive/d/MyWorkSpace3/hello/jni<br />
执行ndk-build<br />
<a href="/blog/wp-content/uploads/2012/01/img3.jpg"><img class="alignnone size-full wp-image-266" title="img3" src="/blog/wp-content/uploads/2012/01/img3.jpg" alt="" width="587" height="324" /></a></p>
<p>生成的lib文件会安装到\libs\armeabi下，名称为libhello.so，但注意在java加载中只用写hello作为lib名称就可以了。</p>
<p><strong>4.检测执行结果</strong></p>
<p>在eclipse中刷新项目，运行，在logcat中应该可以看到“JNITest Native String”</p>
<p>项目附件：<a href='/blog/wp-content/uploads/2012/01/hello.zip'>hello.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2012/01/android-ndk-and-jni/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android EditText强制输入数字</title>
		<link>http://chenyc.info/2011/12/android-edittext_only_digits/</link>
		<comments>http://chenyc.info/2011/12/android-edittext_only_digits/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 09:16:15 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=782</guid>
		<description><![CDATA[需要控制同时软输入法和实体输入法 //控制输入法只能用数字输入法 inputEdit.setInputType(InputType.TYPE_CLASS_PHONE); //设置文本框只接收数字输入，禁止实体键盘输入其他字符 DigitsKeyListener listener = new DigitsKeyListener(); inputEdit.setKeyListener(listener);]]></description>
			<content:encoded><![CDATA[<p>需要控制同时软输入法和实体输入法</p>
<pre>
//控制输入法只能用数字输入法
inputEdit.setInputType(InputType.TYPE_CLASS_PHONE);

//设置文本框只接收数字输入，禁止实体键盘输入其他字符
DigitsKeyListener listener = new DigitsKeyListener();
inputEdit.setKeyListener(listener);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/12/android-edittext_only_digits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android EditText 增加自定义过滤</title>
		<link>http://chenyc.info/2011/12/android-edittext-plus/</link>
		<comments>http://chenyc.info/2011/12/android-edittext-plus/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 09:07:46 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=773</guid>
		<description><![CDATA[在Android中，可以通过对EditText设置setFilters方法，用代码控制EditText的输入长度，或控制输入小数的位数等。 1.设置EditText的输入长度 inputEdit.setFilters(new InputFilter[] { new InputFilter.LengthFilter( length) }); 2.控制输入小数的位数 // 设置小数位数控制 InputFilter lengthfilter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // 删除等特殊字符，直接返回 if (&#34;&#34;.equals(source.toString())) { return null; &#8230; <a href="http://chenyc.info/2011/12/android-edittext-plus/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>在Android中，可以通过对EditText设置setFilters方法，用代码控制EditText的输入长度，或控制输入小数的位数等。</p>
<p style="padding-left: 30px;"><strong>1.设置EditText的输入长度</strong></p>
<pre>
inputEdit.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
				length) });
</pre>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;"><strong>2.控制输入小数的位数</strong></p>
<pre>
		// 设置小数位数控制
		InputFilter lengthfilter = new InputFilter() {
			public CharSequence filter(CharSequence source, int start, int end,
					Spanned dest, int dstart, int dend) {

				// 删除等特殊字符，直接返回
				if (&quot;&quot;.equals(source.toString())) {
					return null;
				}

				String dValue = dest.toString();
				String[] splitArray = dValue.split(&quot;\\.&quot;);
				if (splitArray.length &gt; 1) {
					String dotValue = splitArray[1];
					int diff = dotValue.length() + 1 - digLength;
					if (diff &gt; 0) {
						return source.subSequence(start, end - diff);
					}
				}
				return null;
			}
		};

		inputEdit.setFilters(new InputFilter[] { lengthfilter });
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/12/android-edittext-plus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android LinearLayout根据状态切换图片(模拟按钮的效果）</title>
		<link>http://chenyc.info/2011/12/android_linearlayout_as_button/</link>
		<comments>http://chenyc.info/2011/12/android_linearlayout_as_button/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 14:58:23 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[LinearLayout]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=731</guid>
		<description><![CDATA[在Android中Button可以根据选中，点击等状态切换图片，我想用LinearLayout实现类似的功能， 但是默认情况下pressed状态“容器类”（继承于ViewGroup的类）是接收不到的， 所以LinearLayout的按下就没有效果，后来分析代码，可以通过设置setAddStatesFromChildren 方法获得内部View的状态，就可以取得pressed状态。 linearLayout.setAddStatesFromChildren(true); 还有一个相反的方法setDuplicateParentStateEnabled，内部类获得外部容器类的状态， 这个方法和setAddStatesFromChildren不能同时设置，同时设置会产生异常。]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="宋体">在Android中Button可以根据选中，点击等状态切换图片，我想用LinearLayout实现类似的功能，</font></p>
<p><font size="2" face="宋体">但是默认情况下pressed状态“容器类”（继承于ViewGroup的类）是接收不到的，</font></p>
<p><font size="2"><font face="宋体">所以LinearLayout的按下就没有效果，后来分析代码，可以通过设置<span style="color: #0000ff">setAddStatesFromChildren</span></font></font></p>
<p><span style="color: #0000ff"></span><font size="2" face="宋体">方法获得内部View的状态，就可以取得pressed状态。</font></p>
<blockquote><p><span style="color: #0000ff"><font size="2" face="宋体">linearLayout.setAddStatesFromChildren(true);</font></span></p>
</blockquote>
<p><font size="2" face="宋体"></font></p>
<p><font size="2" face="宋体">还有一个相反的方法<span style="color: #0000ff">setDuplicateParentStateEnabled</span>，内部类获得外部容器类的状态，</font></p>
<p><font size="2" face="宋体">这个方法和<span style="color: #0000ff">setAddStatesFromChildren</span>不能同时设置，同时设置会产生异常。</font></p>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/12/android_linearlayout_as_button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android layout布局相关的注意点</title>
		<link>http://chenyc.info/2011/12/android-layout%e5%b8%83%e5%b1%80%e7%9b%b8%e5%85%b3%e7%9a%84%e6%b3%a8%e6%84%8f%e7%82%b9/</link>
		<comments>http://chenyc.info/2011/12/android-layout%e5%b8%83%e5%b1%80%e7%9b%b8%e5%85%b3%e7%9a%84%e6%b3%a8%e6%84%8f%e7%82%b9/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 14:19:20 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[性能]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=726</guid>
		<description><![CDATA[1.不要过多的嵌套布局，特别是在ListView中需要重复获取的情况下。嵌套布局的情况可以采用RelativeLayout替代LinearLayout,减少嵌套层数。 2.可以采用SDK工具里的hierarchyviewer，分析layout的执行效率。 3.利用新版的ADT(adt1.6)的提示功能，纠正布局文件中影响性能的部分。 4.在采用LinearLayout布局时，尽量不要嵌套中使用layout_weight属性，这会导致所有的内部VIew执行两次measure. 5.对于公用的layout编写,可以采用&#60;merge&#62;作为父标签，这样include到其他layout中后，merge标签不会作为容器，可以减少layout层次。 &#60;merge xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34;&#62; &#60;Button android:layout_width=&#34;fill_parent&#34; android:layout_height=&#34;wrap_content&#34; android:text=&#34;@string/add&#34;/&#62; &#60;Button android:layout_width=&#34;fill_parent&#34; android:layout_height=&#34;wrap_content&#34; android:text=&#34;@string/delete&#34;/&#62; &#60;/merge&#62; 6.采用ViewStub按需加载View &#60;ViewStub     android:id=&#34;@+id/stub_import&#34;     android:inflatedId=&#34;@+id/panel_import&#34;     android:layout=&#34;@layout/progress_overlay&#34;     android:layout_width=&#34;fill_parent&#34;     android:layout_height=&#34;wrap_content&#34;     android:layout_gravity=&#34;bottom&#34; /&#62; 加载方法： View importPanel &#8230; <a href="http://chenyc.info/2011/12/android-layout%e5%b8%83%e5%b1%80%e7%9b%b8%e5%85%b3%e7%9a%84%e6%b3%a8%e6%84%8f%e7%82%b9/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>1.不要过多的嵌套布局，特别是在ListView中需要重复获取的情况下。嵌套布局的情况可以采用<code><a href="http://developer.android.com/reference/android/widget/RelativeLayout.html">RelativeLayout</a>替代<a href="http://developer.android.com/reference/android/widget/LinearLayout.html">LinearLayout</a>,减少嵌套层数。</code></p>
<p>2.可以采用SDK工具里的<code>hierarchyviewer，分析layout的执行效率。</code></p>
<p><img src="http://developer.android.com/images/training/hierarchy-linearlayout.png" alt="" /></p>
<p><img src="http://developer.android.com/images/training/hierarchy-layouttimes.png" alt="" /></p>
<p>3.利用新版的ADT(adt1.6)的提示功能，纠正布局文件中影响性能的部分。</p>
<p>4.在采用<a href="http://developer.android.com/reference/android/widget/LinearLayout.html">LinearLayout</a>布局时，尽量不要嵌套中使用layout_weight属性，这会导致所有的内部VIew执行两次measure.</p>
<p>5.对于公用的layout编写,可以采用&lt;merge&gt;作为父标签，这样include到其他layout中后，merge标签不会作为容器，可以减少layout层次。</p>
<pre>&lt;merge xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;

&lt;Button
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;@string/add&quot;/&gt;

&lt;Button
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;@string/delete&quot;/&gt;

&lt;/merge&gt;</pre>
<p>6.采用ViewStub按需加载View</p>
<pre>&lt;ViewStub
    android:id=&quot;@+id/stub_import&quot;
    android:inflatedId=&quot;@+id/panel_import&quot;
    android:layout=&quot;@layout/progress_overlay&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;bottom&quot; /&gt;</pre>
<p>加载方法：</p>
<pre>
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();
</pre>
<p>加载完成后，ViewStub的Id就不再有效了</p>
<p>7.在ListView中采用ViewHolder保存View的引用，不要重复使用findViewById方法，<br />
这样可加快执行的性能。</p>
<pre>
ViewHolder holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.listitem_image);
holder.text = (TextView) convertView.findViewById(R.id.listitem_text);
holder.timestamp = (TextView) convertView.findViewById(R.id.listitem_timestamp);
holder.progress = (ProgressBar) convertView.findViewById(R.id.progress_spinner);
convertView.setTag(holder);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/12/android-layout%e5%b8%83%e5%b1%80%e7%9b%b8%e5%85%b3%e7%9a%84%e6%b3%a8%e6%84%8f%e7%82%b9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MatrixCursor(转载）</title>
		<link>http://chenyc.info/2011/11/matrixcursor%e8%bd%ac%e8%bd%bd%ef%bc%89/</link>
		<comments>http://chenyc.info/2011/11/matrixcursor%e8%bd%ac%e8%bd%bd%ef%bc%89/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 06:28:08 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://chenyc.info/2011/11/matrixcursor%e8%bd%ac%e8%bd%bd%ef%bc%89/</guid>
		<description><![CDATA[ContentProvider对外共享数据的时候的query()方法是需要一个cursor的。 但是当ContentProvider不是从数据库中去的数据，而又需要返回cursor的时候就需要MatrixCursor。 ContentProvider对外共享数据的时候的query()方法是需要一个cursor的， 但是如果没有数据库，而项目又需要从ContentProvider读取数据的时候怎么办？ 更糟糕的是其他方法操作也都是需要cursor的。 此时就需要MatrixCursor了。相当有趣，它相当于为你模拟了一个表。 @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String[] tableCursor = new String[] { &#34;name&#34;, &#34;job&#34;, &#34;salary&#34; }; MatrixCursor cursor = new MatrixCursor(tableCursor); cursor.addRow(new Object[] { &#34;1111&#34;, &#34;1111&#34;, &#8230; <a href="http://chenyc.info/2011/11/matrixcursor%e8%bd%ac%e8%bd%bd%ef%bc%89/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>ContentProvider对外共享数据的时候的query()方法是需要一个cursor的。<br />
但是当ContentProvider不是从数据库中去的数据，而又需要返回cursor的时候就需要MatrixCursor。</p>
<p>ContentProvider对外共享数据的时候的query()方法是需要一个cursor的，</p>
<p>但是如果没有数据库，而项目又需要从ContentProvider读取数据的时候怎么办？</p>
<p>更糟糕的是其他方法操作也都是需要cursor的。</p>
<p>此时就需要MatrixCursor了。相当有趣，它相当于为你模拟了一个表。</p>
<pre>
	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
	String[] selectionArgs, String sortOrder) {
		String[] tableCursor = new String[] { &quot;name&quot;, &quot;job&quot;, &quot;salary&quot; };
		MatrixCursor cursor = new MatrixCursor(tableCursor);
		cursor.addRow(new Object[] { &quot;1111&quot;, &quot;1111&quot;, &quot;1111&quot; });
		return cursor;
	}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/11/matrixcursor%e8%bd%ac%e8%bd%bd%ef%bc%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>不让ScrollView自动切换子View的焦点</title>
		<link>http://chenyc.info/2011/11/scrollview-dont-change-childview-foucs/</link>
		<comments>http://chenyc.info/2011/11/scrollview-dont-change-childview-foucs/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 04:31:00 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[ScrollView]]></category>

		<guid isPermaLink="false">http://chenyc.info/2011/11/%e4%b8%8d%e8%ae%a9scrollview%e8%87%aa%e5%8a%a8%e5%88%87%e6%8d%a2%e5%ad%90view%e7%9a%84%e7%84%a6%e7%82%b9-2/</guid>
		<description><![CDATA[在开发中，在同一个Activity中有多个输入框，不想让ScrollView自动切换EditText的焦点， 需要继承ScrollView,重写onRequestFocusInDescendants方法,然后在layout中使用自定义的ScrollView即可。 public class NonFocusingScrollView extends ScrollView { public NonFocusingScrollView(Context context) { super(context); } public NonFocusingScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public NonFocusingScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected boolean onRequestFocusInDescendants(int direction, &#8230; <a href="http://chenyc.info/2011/11/scrollview-dont-change-childview-foucs/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>在开发中，在同一个Activity中有多个输入框，不想让ScrollView自动切换EditText的焦点，<br />
需要继承ScrollView,重写onRequestFocusInDescendants方法,然后在layout中使用自定义的ScrollView即可。</p>
<pre>
public class NonFocusingScrollView extends ScrollView {

    public NonFocusingScrollView(Context context) {
        super(context);
    }

    public NonFocusingScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NonFocusingScrollView(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected boolean onRequestFocusInDescendants(int direction,
            Rect previouslyFocusedRect) {
        return true;
    }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/11/scrollview-dont-change-childview-foucs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的豆瓣V1.0发布</title>
		<link>http://chenyc.info/2011/03/mydouban-v1-0/</link>
		<comments>http://chenyc.info/2011/03/mydouban-v1-0/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 16:19:00 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[dobuan]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=214</guid>
		<description><![CDATA[最近由于一些其他事情，没有空写“我的豆瓣”， 暂时移除掉我关注的人等功能，发布第一版先 详细请参考如下地址： http://chenyc.info/mydouban/]]></description>
			<content:encoded><![CDATA[<p>最近由于一些其他事情，没有空写“我的豆瓣”，</p>
<p>暂时移除掉我关注的人等功能，发布第一版先</p>
<p>详细请参考如下地址：</p>
<p><a href="http://chenyc.info/mydouban/">http://chenyc.info/mydouban/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/03/mydouban-v1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Android豆瓣客户端</title>
		<link>http://chenyc.info/2011/02/mydouban/</link>
		<comments>http://chenyc.info/2011/02/mydouban/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 11:25:51 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=156</guid>
		<description><![CDATA[经过2个星期的开发，我的Android豆瓣客户端，基本上查看功能都已完成了 现把界面放上来晒晒～～～～ 豆瓣新书列表 书籍介绍 书籍评论列表 书籍详细评论 图书搜索 我的豆瓣 豆瓣日记 我的资料]]></description>
			<content:encoded><![CDATA[<p>经过2个星期的开发，我的Android豆瓣客户端，基本上查看功能都已完成了<br />
现把界面放上来晒晒～～～～</p>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban1.png"><img class="alignnone size-medium wp-image-157" title="豆瓣新书列表" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban1.png" alt="" width="320" height="480" /></a></p>
<p><strong> 豆瓣新书列表</strong></p>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban2.png"><img class="alignnone size-medium wp-image-158" title="书籍介绍" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban2.png" alt="" width="320" height="480" /></a></p>
<p><strong> 书籍介绍</strong></p>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban3.png"><img class="alignnone size-medium wp-image-159" title="书籍评论列表" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban3.png" alt="" width="320" height="480" /></a></p>
<h6><strong> 书籍评论列表</strong></h6>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban4.png"><img class="alignnone size-medium wp-image-160" title="书籍详细评论" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban4.png" alt="" width="320" height="480" /></a></p>
<p><strong>书籍详细评论</strong></p>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban5.png"><img class="alignnone size-medium wp-image-161" title="图书搜索" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban5.png" alt="" width="320" height="480" /></a></p>
<h6><strong> 图书搜索</strong></h6>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban6.png"><img class="alignnone size-medium wp-image-162" title="我的豆瓣" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban6.png" alt="" width="320" height="480" /></a></p>
<p><strong>我的豆瓣</strong></p>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban7.png"><img class="alignnone size-medium wp-image-163" title="豆瓣日记" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban7.png" alt="" width="320" height="480" /></a></p>
<p><strong>豆瓣日记</strong></p>
<p><a href="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban8.png"><img class="alignnone size-medium wp-image-164" title="我的资料" src="http://chenyc.info/blog/wp-content/uploads/2011/02/mydouban8.png" alt="" width="320" height="480" /></a></p>
<p><strong>我的资料</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2011/02/mydouban/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>编写自己的ContentProvider</title>
		<link>http://chenyc.info/2010/03/create-contentprovider/</link>
		<comments>http://chenyc.info/2010/03/create-contentprovider/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 14:26:14 +0000</pubDate>
		<dc:creator>阳春面</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[ContentProvider]]></category>

		<guid isPermaLink="false">http://chenyc.info/?p=108</guid>
		<description><![CDATA[刚开始看Android NotePad中的ContentProvider的实现时，看的云里雾里，但自己模仿写过一个后，才发现也就这么一回事，就是实现公用的增删改查。下面将需要实现的方法做一个简单的回顾： 1.一个ContentProvider可以实现对多个数据表的操作，但每一个数据表都需要有一个独立URI，也必须有一个独立的类型。URI是其他应用访问这个数据入口，比如： content://com.chenyc.timeaccount.provider/eventtypes/id 它包括4部分，content://就是固定的头部，com.chenyc.timeaccount.provider部分需要一个唯一的字符串，一般就用ContentProiver类所在的包名，eventtypes部分一般是指在这个ContentProvider下，你需要操作那种类型的数据，一般可以用表名来表示，id部分是指具体操作数据的_id，如果查询某一条数据，则id部分就是其在数据库中的_id字段的值。 每个数据表需要有一个独立的数据类型，需要在getType(Uri uri)中实现，返回一个唯一的字符串即可，比如：vnd.chenyc.cursor.dir/vnd.account.eventtype 2.query方法，查询作为最常用的方法，实现也很简单,projection参数代表要查那些列，selection是where条件部分，selectionArgs是where条件部分参数的值,sortOrder指排序，switch部分判断是查一条数据，还是查一个list,然后根据情况进行查询 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case EVENT_TYPES: qb.setTables(EVENT_TYPE_TABLE_NAME); qb.setProjectionMap(sEventTypesProjectionMap); break; case EVENT_TYPE_ID: qb.setTables(EVENT_TYPE_TABLE_NAME); qb.setProjectionMap(sEventTypesProjectionMap); qb.appendWhere(EventTypeAdapter.KEY_ROWID + &#8230; <a href="http://chenyc.info/2010/03/create-contentprovider/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>刚开始看Android NotePad中的ContentProvider的实现时，看的云里雾里，但自己模仿写过一个后，才发现也就这么一回事，就是实现公用的增删改查。下面将需要实现的方法做一个简单的回顾：</p>
<p>1.一个ContentProvider可以实现对多个数据表的操作，但每一个数据表都需要有一个独立URI，也必须有一个独立的类型。URI是其他应用访问这个数据入口，比如：</p>
<p><a title="content://" href="content://">content://</a>com.chenyc.timeaccount.provider/eventtypes/id</p>
<p>它包括4部分，<a title="content://" href="content://">content://</a>就是固定的头部，com.chenyc.timeaccount.provider部分需要一个唯一的字符串，一般就用ContentProiver类所在的包名，eventtypes部分一般是指在这个ContentProvider下，你需要操作那种类型的数据，一般可以用表名来表示，id部分是指具体操作数据的_id，如果查询某一条数据，则id部分就是其在数据库中的_id字段的值。</p>
<p>每个数据表需要有一个独立的数据类型，需要在getType(Uri uri)中实现，返回一个唯一的字符串即可，比如：vnd.chenyc.cursor.dir/vnd.account.eventtype</p>
<p>2.query方法，查询作为最常用的方法，实现也很简单,projection参数代表要查那些列，selection是where条件部分，selectionArgs是where条件部分参数的值,sortOrder指排序，switch部分判断是查一条数据，还是查一个list,然后根据情况进行查询</p>
<pre>
public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {

		SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
		switch (sUriMatcher.match(uri)) {
		case EVENT_TYPES:
			qb.setTables(EVENT_TYPE_TABLE_NAME);
			qb.setProjectionMap(sEventTypesProjectionMap);
			break;
		case EVENT_TYPE_ID:
			qb.setTables(EVENT_TYPE_TABLE_NAME);
			qb.setProjectionMap(sEventTypesProjectionMap);
			qb.appendWhere(EventTypeAdapter.KEY_ROWID + "="
					+ uri.getPathSegments().get(1));
			break;
		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
		}

		SQLiteDatabase db = mDbHelper.getReadableDatabase();
		Cursor c = qb.query(db, projection, selection, selectionArgs, null,
				null, sortOrder);
		c.setNotificationUri(getContext().getContentResolver(), uri);
		return c;
	}
</pre>
<p>3.delete方法，处理方式也跟查询差不多，也分删一个和删一批</p>
<pre>
public int delete(Uri uri, String where, String[] whereArgs) {
		SQLiteDatabase db = mDbHelper.getWritableDatabase();
		int count;
		switch (sUriMatcher.match(uri)) {
		case EVENT_TYPES:
			count = db.delete(EVENT_TYPE_TABLE_NAME, where, whereArgs);
			break;
		case EVENT_TYPE_ID:
			String id = uri.getPathSegments().get(1);
			count = db.delete(EVENT_TYPE_TABLE_NAME,
					EventTypeAdapter.KEY_ROWID
							+ "="
							+ id
							+ (!TextUtils.isEmpty(where) ? " AND (" + where
									+ ')' : ""), whereArgs);
			break;

		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
		}

		getContext().getContentResolver().notifyChange(uri, null);
		return count;
	}
</pre>
<p>4.insert方法，插入成功后需要返回这条记录的URI</p>
<pre>
public Uri insert(Uri uri, ContentValues initialValues) {
		SQLiteDatabase db = mDbHelper.getWritableDatabase();
		long rowId = 0;
		Uri contentUri;
		switch (sUriMatcher.match(uri)) {
		case EVENT_TYPES:
			rowId = db.insert(EVENT_TYPE_TABLE_NAME, "null", initialValues);
			contentUri = TimeAccount.EVENT_TYPE_CONTENT_URI;
			break;
		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
		}

		if (rowId > 0) {
			Uri returnUri = ContentUris.withAppendedId(contentUri, rowId);
			getContext().getContentResolver().notifyChange(returnUri, null);
			return returnUri;
		}
		throw new SQLException("Failed to insert row into " + uri);
	}
</pre>
<p>5.update方法，更新成功后需要返回修改的记录数</p>
<pre>
public int update(Uri uri, ContentValues values, String where,
			String[] whereArgs) {

		SQLiteDatabase db = mDbHelper.getWritableDatabase();
		String id;
		int count;
		switch (sUriMatcher.match(uri)) {
		case EVENT_TYPES:
			count = db.update(EVENT_TYPE_TABLE_NAME, values, where, whereArgs);
			break;
		case EVENT_TYPE_ID:
			id = uri.getPathSegments().get(1);
			count = db.update(EVENT_TYPE_TABLE_NAME, values,
					EventTypeAdapter.KEY_ROWID
							+ "="
							+ id
							+ (!TextUtils.isEmpty(where) ? " AND (" + where
									+ ')' : ""), whereArgs);
			break;
		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
		}
		getContext().getContentResolver().notifyChange(uri, null);
		return count;
	}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chenyc.info/2010/03/create-contentprovider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

