<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Creating a custom CursorAdapter for Android</title>
	<atom:link href="http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/</link>
	<description>Diary and thoughtspace of Rune B. Broberg</description>
	<lastBuildDate>Wed, 26 May 2010 16:29:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Tiger</title>
		<link>http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/comment-page-1/#comment-10702</link>
		<dc:creator>Tiger</dc:creator>
		<pubDate>Thu, 04 Mar 2010 06:23:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cluepusher.dk/?p=194#comment-10702</guid>
		<description>suggestions:
1. Move &quot;LayoutInflater inflater = LayoutInflater.from(context);&quot; to construction to avoid execute it every time.
2. Calling bindView() from newView() is not necessary. bindView() will be called after newView() by the framework.

A custom CursorAdapter from one of my projects:
	protected class ActivityCursorAdapter extends CursorAdapter {
		

		private LayoutInflater mInflater;
		private int mActivityIndex;
		private int mTimeIndex;
		private int mActionIndex;
		private int mAmountIndex;

		public ActivityCursorAdapter(Context context, Cursor c) {
			super(context, c);
			
			mActivityIndex = c.getColumnIndex(Notes.ACTIVITY);
			mTimeIndex = c.getColumnIndex(Notes.TIME);
			mActionIndex = c.getColumnIndex(Notes.ACTION);
			mAmountIndex = c.getColumnIndex(Notes.AMOUNT);
			
			mInflater = LayoutInflater.from(context);
		}

		@Override
		public void bindView(View view, Context context, Cursor cursor) {
			TextView activity = (TextView) view.findViewById(android.R.id.text1);
			TextView time = (TextView) view.findViewById(android.R.id.text2);
			TextView actionAndAmount = (TextView) view.findViewById(R.id.text3);
			
			activity.setText(cursor.getString(mActivityIndex));
			
			long lTime = cursor.getLong(mTimeIndex);
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(lTime);
			time.setText(cal.get(Calendar.HOUR_OF_DAY) + &quot;:&quot; + String.format(&quot;%02d&quot;, cal.get(Calendar.MINUTE)));
			
			String amount = cursor.getString(mAmountIndex);
			if ( amount.length() &gt; 0){
				actionAndAmount.setText(cursor.getString(mActionIndex) + &quot; (&quot; + amount + &quot;)&quot;);
			} else {
				actionAndAmount.setText(cursor.getString(mActionIndex));
			}
		}

		@Override
		public View newView(Context context, Cursor cursor, ViewGroup parent) {
			return mInflater.inflate(R.layout.activityitem_list, null);
		}
		
	}</description>
		<content:encoded><![CDATA[<p>suggestions:<br />
1. Move &#8220;LayoutInflater inflater = LayoutInflater.from(context);&#8221; to construction to avoid execute it every time.<br />
2. Calling bindView() from newView() is not necessary. bindView() will be called after newView() by the framework.</p>
<p>A custom CursorAdapter from one of my projects:<br />
	protected class ActivityCursorAdapter extends CursorAdapter {</p>
<p>		private LayoutInflater mInflater;<br />
		private int mActivityIndex;<br />
		private int mTimeIndex;<br />
		private int mActionIndex;<br />
		private int mAmountIndex;</p>
<p>		public ActivityCursorAdapter(Context context, Cursor c) {<br />
			super(context, c);</p>
<p>			mActivityIndex = c.getColumnIndex(Notes.ACTIVITY);<br />
			mTimeIndex = c.getColumnIndex(Notes.TIME);<br />
			mActionIndex = c.getColumnIndex(Notes.ACTION);<br />
			mAmountIndex = c.getColumnIndex(Notes.AMOUNT);</p>
<p>			mInflater = LayoutInflater.from(context);<br />
		}</p>
<p>		@Override<br />
		public void bindView(View view, Context context, Cursor cursor) {<br />
			TextView activity = (TextView) view.findViewById(android.R.id.text1);<br />
			TextView time = (TextView) view.findViewById(android.R.id.text2);<br />
			TextView actionAndAmount = (TextView) view.findViewById(R.id.text3);</p>
<p>			activity.setText(cursor.getString(mActivityIndex));</p>
<p>			long lTime = cursor.getLong(mTimeIndex);<br />
			Calendar cal = Calendar.getInstance();<br />
			cal.setTimeInMillis(lTime);<br />
			time.setText(cal.get(Calendar.HOUR_OF_DAY) + &#8220;:&#8221; + String.format(&#8220;%02d&#8221;, cal.get(Calendar.MINUTE)));</p>
<p>			String amount = cursor.getString(mAmountIndex);<br />
			if ( amount.length() &gt; 0){<br />
				actionAndAmount.setText(cursor.getString(mActionIndex) + &#8221; (&#8221; + amount + &#8220;)&#8221;);<br />
			} else {<br />
				actionAndAmount.setText(cursor.getString(mActionIndex));<br />
			}<br />
		}</p>
<p>		@Override<br />
		public View newView(Context context, Cursor cursor, ViewGroup parent) {<br />
			return mInflater.inflate(R.layout.activityitem_list, null);<br />
		}</p>
<p>	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tip</title>
		<link>http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/comment-page-1/#comment-9795</link>
		<dc:creator>tip</dc:creator>
		<pubDate>Thu, 14 Jan 2010 16:02:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cluepusher.dk/?p=194#comment-9795</guid>
		<description>Why do you call bindView() in newView()?  It seems to then be called twice, at least on the emulator.
Don&#039;t see much info on CursorAdapter.  Thanks for the info.</description>
		<content:encoded><![CDATA[<p>Why do you call bindView() in newView()?  It seems to then be called twice, at least on the emulator.<br />
Don&#8217;t see much info on CursorAdapter.  Thanks for the info.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: landry</title>
		<link>http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/comment-page-1/#comment-9696</link>
		<dc:creator>landry</dc:creator>
		<pubDate>Sun, 03 Jan 2010 18:59:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cluepusher.dk/?p=194#comment-9696</guid>
		<description>Thanks a lot !
I was so annoyed trying to figure out how to implement a CursorAdapter ;-)</description>
		<content:encoded><![CDATA[<p>Thanks a lot !<br />
I was so annoyed trying to figure out how to implement a CursorAdapter <img src='http://blog.cluepusher.dk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
