tag:blogger.com,1999:blog-44883657820257606352024-03-13T18:04:42.502-07:00Android IdeasAndroid learning experience, tips and more...Unknownnoreply@blogger.comBlogger26125tag:blogger.com,1999:blog-4488365782025760635.post-16757688685228774212012-09-28T13:50:00.001-07:002012-10-03T08:37:36.660-07:00No resource identifier found for attribute 'indicator_gravity' in package ….I was trying to porting the <a href="http://code.google.com/p/tree-view-list-android/" target="_blank">Tree-View-List-Android</a> into my project recently. I have created a project called com.dotnetideas.treeview and added everything in. I can run the demo without any issue. But when I use it in another project, I kept getting “No resource identifier found for attribute 'indicator_gravity' in package com.dotnetideas.treeview” in main_demo.xml.<br />
Here is the xml looks like. <br />
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;"><?</span><span style="color: maroon;">xml</span> <span style="color: red;">version</span><span style="color: blue;">="1.0"</span> <span style="color: red;">encoding</span><span style="color: blue;">="utf-8"</span>?<span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">LinearLayout</span> <span style="color: red;">xmlns:android</span><span style="color: blue;">="http://schemas.android.com/apk/res/android"</span> <span style="color: red;">xmlns:treeView</span><span style="color: blue;">="http://schemas.android.com/apk/res/com.dotnetideas.treeview"</span>
<span style="color: red;">android:orientation</span><span style="color: blue;">="vertical"</span> <span style="color: red;">android:layout_width</span><span style="color: blue;">="fill_parent"</span> <span style="color: red;">android:layout_height</span><span style="color: blue;">="fill_parent"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">ListView</span> <span style="color: red;">android:layout_width</span><span style="color: blue;">="0dip"</span> <span style="color: red;">android:layout_height</span><span style="color: blue;">="0dip"</span> <span style="color: red;">android:scrollbars</span><span style="color: blue;">="vertical"</span>
<span style="color: red;">android:visibility</span><span style="color: blue;">="gone"</span><span style="color: blue;">></span> <span style="color: green;"><!-- Just to test some attributes in IDE --></span>
<span style="color: blue;"></</span><span style="color: maroon;">ListView</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">pl.polidea.treeview.TreeViewList</span> android:id="@+id/mainTreeView" android:layout_width="fill_parent"
android:layout_height="fill_parent" treeView:indicator_gravity="right|center_vertical"
android:scrollbars="vertical" android:smoothScrollbar="true"<span style="color: blue;">/></span>
<span style="color: blue;"></</span><span style="color: maroon;">LinearLayout</span><span style="color: blue;">></span></pre>
Although I followed the old code to changed the xml namespace from xmlns:treeView=<a href="http://schemas.android.com/apk/res/pl.polidea.treeview">http://schemas.android.com/apk/res/pl.polidea.treeview</a> to xmlns:treeView=<a href="http://schemas.android.com/apk/res/com.dotnetideas.treeview">http://schemas.android.com/apk/res/com.dotnetideas.treeview</a>. It doesn’t seem like valid xml namespace. It turned out that the namespace needs to be <a href="xmlns:treeView="http://com.dotnetideas.treeview/apk/res/treeview"" title="xmlns:treeView="http://com.dotnetideas.treeview/apk/res/treeview"">xmlns:treeView="</a><a href="http://schemas.android.com/apk/res/com.dotnetideas.treeview">http://schemas.android.com/apk/res</a>-auto" if we reference as a library project.</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-4488365782025760635.post-61417338377170158092011-07-12T08:38:00.000-07:002011-08-30T08:39:15.881-07:00AlarmManager and NotificationManager sample code<h4>This is not a complete tutorial on how to use AlarmManager and NotificationManager, but a simple sample.</h4>The scenario is I want to have an alarm set to certain time. When it goes off, it show notification icon on status bar. When click on the notification, it will start an activity.<br> <h2>1. Create the BroadcastReceiver</h2> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: blue">public</span> <span style="color: blue">class</span> AlarmReceiver <span style="color: blue">extends</span> BroadcastReceiver {
@Override
<span style="color: blue">public</span> <span style="color: blue">void</span> onReceive(Context context, Intent intent) {
NotificationManager mNM;
mNM = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
<span style="color: green">// Set the icon, scrolling text and timestamp</span>
Notification notification = <span style="color: blue">new</span> Notification(R.drawable.icon, <span style="color: #006080">"Test Alarm"</span>,
System.currentTimeMillis());
<span style="color: green">// The PendingIntent to launch our activity if the user selects this notification</span>
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, <span style="color: blue">new</span> Intent(context, TestActivity.<span style="color: blue">class</span>), 0);
<span style="color: green">// Set the info for the views that show in the notification panel.</span>
notification.setLatestEventInfo(context, context.getText(R.string.alarm_service_label), <span style="color: #006080">"This is a Test Alarm"</span>, contentIntent);
<span style="color: green">// Send the notification.</span>
<span style="color: green">// We use a layout id because it is a unique number. We use it later to cancel.</span>
mNM.notify(R.string.alarm_service_label, notification);
}
}</pre><br></div>
<h2>2. Add Receiver to Manifest.xml</h2>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: blue"><</span><span style="color: maroon">receiver</span> <span style="color: red">android:process</span><span style="color: blue">=":remote"</span> <span style="color: red">android:name</span><span style="color: blue">="AlarmReceiver"</span><span style="color: blue">></</span><span style="color: maroon">receiver</span><span style="color: blue">></span></pre><br></div>
<h2>3. Set the alarm</h2>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: blue">public</span> <span style="color: blue">class</span> AlarmService {
<span style="color: blue">private</span> Context context;
<span style="color: blue">private</span> PendingIntent mAlarmSender;
<span style="color: blue">public</span> AlarmService(Context context) {
<span style="color: blue">this</span>.context = context;
mAlarmSender = PendingIntent.getBroadcast(context, 0, <span style="color: blue">new</span> Intent(context, AlarmReceiver.<span style="color: blue">class</span>), 0);
}
<span style="color: blue">public</span> <span style="color: blue">void</span> startAlarm(){
<span style="color: green">//Set the alarm to 10 seconds from now</span>
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, 10);
<span style="color: blue">long</span> firstTime = c.getTimeInMillis();
<span style="color: green">// Schedule the alarm!</span>
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, firstTime, mAlarmSender);
}
}</pre><br></div> Unknownnoreply@blogger.com12tag:blogger.com,1999:blog-4488365782025760635.post-85927179906102595342011-07-12T07:51:00.001-07:002011-08-30T07:52:37.673-07:00How to use and customize tab(image, font)?<h2>1. Create tabs</h2> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br>TabHost tabHost = getTabHost(); <span style="color: #008000">// The activity TabHost</span><br>TabHost.TabSpec spec; <span style="color: #008000">// Resusable TabSpec for each tab</span><br>Intent intent; <span style="color: #008000">// Reusable Intent for each tab</span><br><span style="color: #008000">// Create an Intent to launch an Activity for the tab (to be reused)</span><br>intent = <span style="color: #0000ff">new</span> Intent().setClass(<span style="color: #0000ff">this</span>, TaskActivity.<span style="color: #0000ff">class</span>);<br><span style="color: #008000">// Initialize a TabSpec for each tab and add it to the TabHost</span><br>spec = tabHost.newTabSpec(<span style="color: #006080">"task"</span>).setIndicator(<span style="color: #006080">"Task"</span>, null).setContent(intent);<br>tabHost.addTab(spec); <span style="color: #008000">// Do the same for the other tabs</span><br>intent = <span style="color: #0000ff">new</span> Intent().setClass(<span style="color: #0000ff">this</span>, CalendarActivity.<span style="color: #0000ff">class</span>);<br>spec = tabHost.newTabSpec(<span style="color: #006080">"calendar"</span>).setIndicator(<span style="color: #006080">"Calendar"</span>, null).setContent(intent);<br>tabHost.addTab(spec); </pre><br></div>
<h2>2. Customize tabs</h2>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br><div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">TabHost tabHost = getTabHost();<br>LinearLayout linearLayout = (LinearLayout) tabHost.getChildAt(0); <br>TabWidget tw = (TabWidget) linearLayout .getChildAt(0);<br>RelativeLayoutfirstTabLayout = (RelativeLayout) tw.getChildAt(0); <br><span style="color: #008000">//First tab</span><br>TextViewtabHeader = (TextView) firstTabLayout .getChildAt(1); <br>tabHeader .setTextSize(18); <span style="color: #008000">//Change text size</span><br>tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 36; <br><span style="color: #008000">//Change first tab header height</span><br>firstTabLayout.setBackgroundResource(R.drawable.group_background_overdue);<br>tabHeader.setText(<span style="color: #006080">"Tab page 1"</span>);</pre><br></div></pre><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-76908459007762028462011-07-12T07:51:00.000-07:002011-08-30T07:52:01.261-07:00How to sort array list?<h2>Sort by simple type property</h2> <p>1. Implement the Comparable interface</p> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Item <span style="color: #0000ff">implements</span> Comparable<Item> {<br>…<br>}</pre><br></div>
<p>2. Implement the compareTo method. </p>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br>@Override<br><span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> compareTo(Item another) {<br> <span style="color: #008000">//Compare the name</span><br> <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.name.compareTo(another.name);<br>}</pre><br></div>
<p>3. Call sort</p>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br>List<Item> items = ..<br>items.sort();</pre><br></div>
<h2>Sort by user defined property</h2>
<p>1. Create a new class</p>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br><span style="color: #0000ff">import</span> java.util.Comparator;<br><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ItemCompareByLocation <span style="color: #0000ff">implements</span> Comparator<Item>{<br> @Override<br> <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> compare(Item arg0, Item arg1) {<br> <span style="color: #0000ff">return</span> arg0.getLocation().compareTo(arg1.getLocation());<br> }<br>}</pre><br></div>
<p>2. Call sort</p>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br>Collections.sort(items, <span style="color: #0000ff">new</span> ItemCompareByLocation());</pre><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-35290167927772140372011-07-12T07:50:00.000-07:002011-08-30T07:51:06.839-07:00How to use Style<h2>Create style.xml</h2> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span><br><span style="color: #0000ff"><</span><span style="color: #800000">resources</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">style</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="DetailTextView"</span> <span style="color: #ff0000">parent</span><span style="color: #0000ff">="@android:style/TextAppearance"</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:layout_width"</span><span style="color: #0000ff">></span>wrap_content<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:layout_height"</span><span style="color: #0000ff">></span>wrap_content<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:textSize"</span><span style="color: #0000ff">></span>14sp<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:textStyle"</span><span style="color: #0000ff">></span>bold<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"></</span><span style="color: #800000">style</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">style</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="DateTimeButton"</span> <span style="color: #ff0000">parent</span><span style="color: #0000ff">="@android:style/Widget.Button"</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:layout_width"</span><span style="color: #0000ff">></span>fill_parent<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:layout_height"</span><span style="color: #0000ff">></span>wrap_content<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:gravity"</span><span style="color: #0000ff">></span>left|center_vertical<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">item</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="android:textSize"</span><span style="color: #0000ff">></span>19sp<span style="color: #0000ff"></</span><span style="color: #800000">item</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"></</span><span style="color: #800000">style</span><span style="color: #0000ff">></span><br><span style="color: #0000ff"></</span><span style="color: #800000">resources</span><span style="color: #0000ff">></span></pre><br></div>
<h2>Use it in layout</h2>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br><span style="color: #0000ff"><</span><span style="color: #800000">TextView</span> <span style="color: #ff0000">android:id</span><span style="color: #0000ff">="@+id/TextView01"</span> <span style="color: #ff0000">android:text</span><span style="color: #0000ff">="What"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="@style/DetailTextView"</span> <span style="color: #0000ff">/></span></pre><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-68684011494701837752011-07-12T07:00:00.000-07:002011-08-30T07:01:20.612-07:00How to show toast?<h2>Simple toast:</h2> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br>Context context = getApplicationContext();<br>CharSequence text = <span style="color: #006080">"Hello toast!"</span>;<br><span style="color: #0000ff">int</span> duration = Toast.LENGTH_SHORT;<br>Toast toast = Toast.makeText(context, text, duration);<br>toast.show();</pre><br></div>
<h2>Customized toast:</h2>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br>LayoutInflater inflater;<br>inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br>View layout = inflater.inflate(R.layout.detail_toast, <br>(ViewGroup)arg0.findViewById(R.id.toast_layout_root));<br>TextView taskTextView = (TextView) <br>layout.findViewById(R.id.taskTextView);<br>taskTextView.setText(task.getName());<br>TextView detailTextView = (TextView) <br>layout.findViewById(R.id.detailTextView);<br>detailTextView.setText(sb.toString());<br>Toast toast = <span style="color: #0000ff">new</span> Toast(context.getApplicationContext());<br>toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);<br>toast.setDuration(Toast.LENGTH_LONG);<br>toast.setView(layout);<br>toast.show();</pre><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-17100234601907307342010-11-10T05:56:00.000-08:002011-08-30T06:59:03.489-07:00How to customize control<p>There are some icons and xmls under C:\Android\android-sdk-windows-1.6_r1\platforms\android-1.5(or other version)\data\res\drawable</p> <p>To use different icons for standard control, we can copy the xml file and icons used in the xml to our own \drawable folder and set it in the layout xml</p> <p>1) Grab the checkbox_background.xml and checkbox.xml from above folder and copy to the drawable folder in my project</p> <p>2) Copy all the PNG files for the checkbox to the drawable folder in my project</p> <p><a href="http://lh4.ggpht.com/-F2pkOrdMONY/TlzsaxZYB1I/AAAAAAAAAis/j-RHEnOvndI/s1600-h/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-pxnt9gI2DEk/TlzsbFs-bSI/AAAAAAAAAiw/B94HCrKgSP4/image_thumb.png?imgmax=800" width="244" height="173"></a> </p> <p>3) Change the layout to use the checkbox (In my case, it is a CheckedTextView)</p> <p>android:checkMark="@drawable/checkbox"</p> <p><a href="http://lh4.ggpht.com/-jyGctEwqZpQ/TlzsbSwiwHI/AAAAAAAAAi0/Nrvc2Nj-We0/s1600-h/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-5zmt283wbUc/TlzsbhVZVoI/AAAAAAAAAi4/HcCOEpcf6Y4/image_thumb1.png?imgmax=800" width="184" height="77"></a></p> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-52799861144682446432010-10-25T06:50:00.000-07:002011-08-30T06:59:54.702-07:00java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap<p>Recently our two applications on Android Market kept reporting error “java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap…”. If you look at the stack trace, there is no trace of our code. Below is one of the stack trace:</p> <p>java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@4478a900 <br>at android.graphics.Canvas.throwIfRecycled(Canvas.java:955) <br>at android.graphics.Canvas.drawBitmap(Canvas.java:1044) <br>at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:323) <br>at android.widget.ImageView.onDraw(ImageView.java:842) <br>at android.view.View.draw(View.java:6740) <br>at android.view.ViewRoot.draw(ViewRoot.java:1407) <br>at android.view.ViewRoot.performTraversals(ViewRoot.java:1163) <br>at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) <br>at android.os.Handler.dispatchMessage(Handler.java:99) <br>at android.os.Looper.loop(Looper.java:123) <br>at android.app.ActivityThread.main(ActivityThread.java:4627) <br>at java.lang.reflect.Method.invokeNative(Native Method) <br>at java.lang.reflect.Method.invoke(Method.java:521) <br>at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) <br>at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) <br>at dalvik.system.NativeStart.main(Native Method)</p> <p> </p> <p>After searching around the Internet, I found some clues. It has something to do with the call of bitmap.recycle(). Some people suggest to remove all the calls to bitmap.recycle() and let the garbage collector to do the job. So I tried this solution and updated the Packing List application. I will give it a day or two to see if it settles the issue.</p> Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-4488365782025760635.post-88062563578607353852010-08-19T20:01:00.001-07:002010-08-19T20:02:17.790-07:00Miscellaneous Tips<h4><a name="_Toc267852159">How to stretch a control</a>?</h4> <p>Set Layout_weight to greater than 0</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9rfxJv6ahlJW4FocBslL6DAZnF41PcEyaPZED9hVU-5x_-i9Sf40IyCzrsm7xlJMTTnZml69_67uHxHpovkI942Yw5CnKtsTumPtI34VC97B8FLaNljknNpSmbPD1Xy9xSH1wyKjqiys/s1600-h/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/TG3v6YPQyaI/AAAAAAAAAhk/nEc0HR7iZVg/image_thumb.png?imgmax=800" width="254" height="42"></a> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGSUrQaVMe3Gl0UBk0hmbhSmJQQZB1EkKx-0EmJw1d15bJUyodA1Tn5g6pddm_3S36CXy7bjBplysaXnFTuOYLTd9GQ0GCwCmgUcvDUiEQ4S2E87FpQQzK1Ty_gWnaRJcT1puAejzh1t8/s1600-h/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihezRuM2utlX-auE6TsnKGb4MGRtJH5ErHkCPZUMWXxlMrTyUHvu6SLbzqIGHwKKQMFuunJcIbpm6JmGPKPL8bAfsqnxn5b26emcIQTAXpin201sHJYJKGq_JztgtXjTqm8uEv5G5GGEM/?imgmax=800" width="244" height="27"></a> <h4> </h4> <h4><a name="_Toc267852160">Issue with Check box in a list view</a></h4> <p>When I use anything other than textview in a listview, the context menu stop working. Now to have a check box in a list view, I have to use CheckedTextView. But the text in CheckedTextView appears on the left side of the checkbox. I don’t know how to change it, so I use a CheckedTextView with no text and a TextView. <h4> </h4> <h4><a name="_Toc267852161">Show checkbox in CheckedTextView</a></h4> <div id="codeSnippetWrapper"> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">CheckedTextView</span> <span style="color: #ff0000">android:id</span><span style="color: #0000ff">="@+id/categoryCheckedTextView"</span><br> <span style="color: #ff0000">android:layout_width</span><span style="color: #0000ff">="wrap_content"</span> <br> <span style="color: #ff0000">android:checkMark</span><span style="color: #0000ff">="?android:attr/listChoiceIndicatorMultiple"</span><br> <span style="color: #ff0000">android:layout_height</span><span style="color: #0000ff">="wrap_content"</span> <br> <span style="color: #ff0000">android:clickable</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">></span><br><span style="color: #0000ff"></</span><span style="color: #800000">CheckedTextView</span><span style="color: #0000ff">></span></pre><br></div></div>
<h4>Display simple <a name="_Toc267852164">MessageBox in Android</a></h4>
<div><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><br>AlertDialog alertDialog;<br>alertDialog = <span style="color: #0000ff">new</span> AlertDialog.Builder(<span style="color: #0000ff">this</span>).create();<br>alertDialog.setTitle(<span style="color: #006080">"Packing List"</span>);<br>alertDialog.setMessage(<span style="color: #006080">"Could not find the file."</span>);<br>alertDialog.show();</pre></div>
<h4> </h4>
<h4><a name="_Toc267852171">Change emulator orientation</a></h4>
<p>Use<strong> KEYPAD_7 </strong>or <strong>KEYPAD_9</strong> on you desktop. You need to<strong> turn off your Num Lock.</strong>
<div><br></div>
<h4><a name="_Toc267852175">Dynamically change the background color</a></h4>
<p>To dynamically change the background color, use myView.setBackgroundResource(R.color.my_color) instead myView.setBackgroundColor(R.color.my_color)
<h4> </h4>
<h4>How to align text in text view?</h4>When trying to align the text to the right in text , set the “layout_gravity” to right doesn’t work. Need to set “gravity” to right.
<div id="codeSnippetWrapper"><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-29792046466663978992010-08-09T13:09:00.001-07:002010-08-09T13:09:45.693-07:00Re-import Android project issue<p>After my laptop crashes, I have to re-install everything. After importing the existing projects, I got the following error “The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override superclass method” <p><a href="http://lh4.ggpht.com/_ElXg_EOWn5c/TGBggRkyWJI/AAAAAAAAAhQ/sN4eENYvha8/s1600-h/image%5B11%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiljO0-ZPtzUF2BWQUNjsdouAXiAx-8x677uXf5dQPx9p6xHDxKDX5meJkeYps4mTzyVo9ejo_8-kyfYKc8az-TlhRKQJT3mjfxfvsAAXo5ri6oS2PwRSElZ1WjVTlTThT4E_l4aY8lTmY/?imgmax=800" width="545" height="318"></a> </p> <p>And this is what I found on google: <p><i>Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 can be annotated with @Override, but in Java 1.5 can only be applied to methods overriding a superclass method). </i> <p><i>Go to your project/ide preferences and set the java compiler level to 1.6 and also make sure you select JRE 1.6 to execute your program from eclipse.</i></p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNBDruaS5XmiKw_lnyRknl8kRZ4fwrKeXBXE-1nriJvc3IKxGoPjGYLG_qMHzVWRUkL_yrVGJ-DvYkBuBRTZI5Ir58wQEeDuK4J7kCAi4DleniSbHbwY-ogCL373TwKNhIoVkjXkySO30/s1600-h/image%5B8%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/TGBgiJi5HlI/AAAAAAAAAhc/Iwi-pi0FOP4/image_thumb%5B4%5D.png?imgmax=800" width="376" height="363"></a> Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-4488365782025760635.post-45256378829949219072010-08-09T12:37:00.001-07:002010-08-09T12:37:52.794-07:00How to debug on device?<p>For detail information, go to - <a href="http://developer.android.com/guide/developing/device.html">http://developer.android.com/guide/developing/device.html</a>. The following is a simplified version for my own reference. <p>1. Declare your application as "debuggable" in your Android Manifest. <p>In Eclipse, you can do this from the <b>Application</b> tab when viewing the Manifest (on the right side, set <b>Debuggable</b> to <em>true</em>). Otherwise, in the <code>AndroidManifest.xml</code> file, add <code>android:debuggable="true"</code> to the <code><application></code> element. <p>2. Turn on "USB Debugging" on your device. <p>On the device, go to the home screen, press <b>MENU</b>, select <b>Applications</b> > <b>Development</b>, then enable <b>USB debugging</b>. <p>3. Setup your system to detect your device. <p>If you're developing on Windows, you need to install a USB driver for adb. See the <a href="http://developer.android.com/sdk/win-usb.html">Windows USB Driver</a> documentation. <p><a href="http://lh5.ggpht.com/_ElXg_EOWn5c/TGBZDDqAvgI/AAAAAAAAAhI/i1B2A6OhOX4/s1600-h/image%5B2%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/TGBZD6WTQYI/AAAAAAAAAhM/-ZR4Vph4fJY/image_thumb.png?imgmax=800" width="244" height="118"></a> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-75907336283317942572010-08-09T12:06:00.001-07:002010-08-09T12:06:53.120-07:00ClassNotFound exception when unmarshalling<p>The following code is the serialization part of the Category class in PackingList project. Since the category has an arraylist of items, I have to put it in Bundle. To de-serialize it, I need to retrieve items from the Bundle. To do that, I was using Bundle d = in.readBundle(). However, I received “ClassNotFound exception when unmarshalling”. I have to pass in the ClassLoader so it knows it’s for the Item. <p> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">@Override<br><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> writeToParcel(Parcel dest, <span style="color: #0000ff">int</span> flags) {<br> dest.writeString(category);<br> Bundle b = <span style="color: #0000ff">new</span> Bundle();<br> b.putParcelableArrayList(<span style="color: #006080">"items"</span>, items);<br> dest.writeBundle(b);<br> <br>}<br><br><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">final</span> Parcelable.Creator<Category> CREATOR = <br> <span style="color: #0000ff">new</span> Parcelable.Creator<Category>() { <br> <span style="color: #0000ff">public</span> Category createFromParcel(Parcel in) { <br> Category category = <span style="color: #0000ff">new</span> Category();<br> category.category = in.readString();<br> Bundle b = in.readBundle(Item.<span style="color: #0000ff">class</span>.getClassLoader()); <br> category.items = b.getParcelableArrayList(<span style="color: #006080">"items"</span>);<br> <br> <span style="color: #0000ff">return</span> category;<br> }<br><br> @Override<br> <span style="color: #0000ff">public</span> Category[] newArray(<span style="color: #0000ff">int</span> size) {<br> <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> Category[size];<br> }<br>};</pre><br></div> Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-4488365782025760635.post-39118158412114052032010-08-09T11:57:00.001-07:002010-08-09T11:57:54.755-07:00How to display progress dialog?<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> ProgressDialog dialog;<br><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> onCreate(Bundle savedInstanceState) { <br> ……<br> <br> dialog = ProgressDialog.show(<span style="color: #0000ff">this</span>, <span style="color: #006080">""</span>, <br> <span style="color: #006080">"Loading Calendar and Tasks. Please wait..."</span>, true);<br> <br> ……<br> CalendarThread calendarThread = <span style="color: #0000ff">new</span> CalendarThread();<br> calendarThread.start(); <br> <br>}<br><br><span style="color: #0000ff">private</span> <span style="color: #0000ff">class</span> CalendarThread <span style="color: #0000ff">extends</span> Thread { <br> <br> @Override <br> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> run() { <br> <span style="color: #008000">//Long running process</span><br> ……<br><br> handler.sendEmptyMessage(0); <br> } <br><br> <span style="color: #0000ff">private</span> Handler handler = <span style="color: #0000ff">new</span> Handler() { <br><br> @Override <br> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> handleMessage(Message msg) { <br> <span style="color: #008000">//Process after the long running process</span><br> ……<br> dialog.dismiss(); <br> } <br> }; <br>}</pre><br></div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-3632977490696184602010-04-21T10:07:00.001-07:002010-06-18T08:51:26.605-07:00Android Emulator IssueYesterday I resumed the work on improving the Packing List 1.5. However, the Emulator didn’t corporate. It kept crashing. I was so frustrated. I deleted and re-created the image several times. It still didn’t work. The error I received was something like "sad result from adb". What does “sad result” mean? They really should give it better description. Some times I received “the user data image is used by another emulator” while there was only one emulator and one user. I googled and no help. Finally, this morning I tried again, the emulator was so slow to start. So I checked the power mode on my laptop. It turned out I accidently set the power mode to “Power Saver” a couple of days ago. I changed it back. Now everything worked just fine!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-49573120154981629992010-02-08T08:40:00.001-08:002010-08-09T12:13:54.137-07:00Creating custom dialog in AndroidThis blog shows you an example on how to create custom dialog. For more information on creating different kind of dialogs, please visit <a href="http://developer.android.com/guide/topics/ui/dialogs.html">http://developer.android.com/guide/topics/ui/dialogs.html</a><br>1. Create layout for the dialog<br> <div id="codeSnippetWrapper"> <div id="codeSnippetWrapper"> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><?xml version=<span style="color: #006080">"1.0"</span> encoding=<span style="color: #006080">"utf-8"</span>?><br><LinearLayout<br> xmlns:android=<span style="color: #006080">"http://schemas.android.com/apk/res/android"</span><br> android:layout_width=<span style="color: #006080">"fill_parent"</span> <br> android:layout_height=<span style="color: #006080">"fill_parent"</span> <br> android:orientation=<span style="color: #006080">"vertical"</span> <br> android:padding=<span style="color: #006080">"10sp"</span>><br> <EditText android:text=<span style="color: #006080">""</span> <br> android:id=<span style="color: #006080">"@+id/categoryEditText"</span> <br> android:layout_height=<span style="color: #006080">"wrap_content"</span> <br> android:layout_width=<span style="color: #006080">"fill_parent"</span> <br> android:singleLine=<span style="color: #006080">"true"</span>><br> </EditText> <br></LinearLayout></pre><br></div><br></div><br></div>
<div>2. Override onCreateDialog in the Activity</div>
<div></div>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">@Override<br><span style="color: #0000ff">protected</span> Dialog onCreateDialog(<span style="color: #0000ff">int</span> id) {<br> <span style="color: #0000ff">switch</span> (id) {<br> <span style="color: #0000ff">case</span> CATEGORY_DETAIL:<br> LayoutInflater li = LayoutInflater.from(<span style="color: #0000ff">this</span>);<br> View categoryDetailView = li.inflate(R.layout.category_detail, null);<br> <br> AlertDialog.Builder categoryDetailBuilder = <span style="color: #0000ff">new</span> AlertDialog.Builder(<span style="color: #0000ff">this</span>);<br> categoryDetailBuilder.setTitle(<span style="color: #006080">"Edit Category"</span>);<br> categoryDetailBuilder.setView(categoryDetailView);<br> AlertDialog categoryDetail = categoryDetailBuilder.create();<br> <br> categoryDetail.setButton(<span style="color: #006080">"OK"</span>, <span style="color: #0000ff">new</span> OnClickListener(){<br> <br> @Override<br> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> onClick(DialogInterface dialog, <span style="color: #0000ff">int</span> which) {<br> AlertDialog categoryDetail = (AlertDialog)dialog;<br> EditText et = (EditText)categoryDetail.findViewById(R.id.categoryEditText);<br> <span style="color: #0000ff">if</span> (categories.get(selectedIndex)!=null){<br> <span style="color: #008000">//... some code</span><br> } <br> });<br> <br> categoryDetail.setButton2(<span style="color: #006080">"Cancel"</span>, <span style="color: #0000ff">new</span> DialogInterface.OnClickListener() {<br> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> onClick(DialogInterface dialog, <span style="color: #0000ff">int</span> which) {<br> <span style="color: #0000ff">return</span>;<br> }}); <br> <br> <span style="color: #0000ff">return</span> categoryDetail;<br> <span style="color: #0000ff">default</span>:<br> <span style="color: #0000ff">break</span>;<br> }<br> <span style="color: #0000ff">return</span> null;<br>}</pre><br></div><br></div>
<div>3. Override onPrepareDialog to dynamically set default value before the dialog is open</div>
<div></div>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">@Override<br><span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> onPrepareDialog(<span style="color: #0000ff">int</span> id, Dialog dialog) {<br> <span style="color: #0000ff">switch</span> (id) {<br> <span style="color: #0000ff">case</span> CATEGORY_DETAIL:<br> AlertDialog categoryDetail = (AlertDialog)dialog;<br> EditText et = (EditText)categoryDetail.findViewById(R.id.categoryEditText);<br> et.setText(defaultValue);<br> <span style="color: #0000ff">break</span>;<br> <span style="color: #0000ff">default</span>:<br> <span style="color: #0000ff">break</span>;<br> }<br>}</pre><br></div><br></div>4. Call showDialog to display the dialog<br>
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: blue">static</span> <span style="color: blue">final</span> <span style="color: blue">private</span> <span style="color: blue">int</span> CATEGORY_DETAIL = 1;
<span style="color: green">//... some code</span>
showDialog(CATEGORY_DETAIL);</pre><br></div>
<div id="codeSnippetWrapper"><br></div> Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-4488365782025760635.post-37457066033893556192010-02-01T12:18:00.001-08:002010-06-18T08:52:34.596-07:00Passing a list of objects between ActivitiesIn Android, you can use Bundle to pass data between activities. There are many functions to pass Integer, String, etc. To pass an object, you will need to implement Parcelable interface and override some functions to serialize/de-serialize the object. Here is an example:<br />
<div id="codeSnippetWrapper"><div id="codeSnippetWrapper"><pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> Category <span style="color: blue;">implements</span> Parcelable {
<span style="color: blue;">private</span> String category;
<span style="color: blue;">private</span> ArrayList<Item> items;
<span style="color: blue;">public</span> String getCategory() {
<span style="color: blue;">return</span> category;
}
<span style="color: blue;">public</span> <span style="color: blue;">void</span> setCategory(String category) {
<span style="color: blue;">this</span>.category = category;
}
<span style="color: blue;">public</span> ArrayList<Item> getItems() {
<span style="color: blue;">return</span> items;
}
<span style="color: blue;">public</span> <span style="color: blue;">void</span> setItems(ArrayList<Item> items) {
<span style="color: blue;">this</span>.items = items;
}
<span style="color: blue;">public</span> Category(){
}
<span style="color: blue;">public</span> Category(String _category){
category = _category;
}
@Override
<span style="color: blue;">public</span> <span style="color: blue;">int</span> describeContents() {
<span style="color: blue;">return</span> 0;
}
@Override
<span style="color: blue;">public</span> <span style="color: blue;">void</span> writeToParcel(Parcel dest, <span style="color: blue;">int</span> flags) {
dest.writeString(category);
Bundle b = <span style="color: blue;">new</span> Bundle();
b.putParcelableArrayList(<span style="color: #006080;">"items"</span>, items);
dest.writeBundle(b);
}
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">final</span> Parcelable.Creator<Category> CREATOR =
<span style="color: blue;">new</span> Parcelable.Creator<Category>() {
<span style="color: blue;">public</span> Category createFromParcel(Parcel in) {
Category category = <span style="color: blue;">new</span> Category();
category.category = in.readString();
Bundle b = in.readBundle(Item.<span style="color: blue;">class</span>.getClassLoader());
category.items = b.getParcelableArrayList(<span style="color: #006080;">"items"</span>);
<span style="color: blue;">return</span> category;
}
@Override
<span style="color: blue;">public</span> Category[] newArray(<span style="color: blue;">int</span> size) {
<span style="color: blue;">return</span> <span style="color: blue;">new</span> Category[size];
}
};
}</pre><br />
</div><br />
</div>To pass an arraylist of Category to another activity, <br />
<div id="codeSnippetWrapper"><pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;">intent i = <span style="color: blue;">new</span> Intent(_av.getContext(), ItemList.<span style="color: blue;">class</span>);
Bundle b = <span style="color: blue;">new</span> Bundle();
b.putParcelableArrayList(<span style="color: #006080;">"categories"</span>, categories);
b.putInt(<span style="color: #006080;">"index"</span>, _index);
i.putExtras(b);
startActivityForResult(i, ITEM_LIST);</pre><br />
</div>To retrieve the data,<br />
<div id="codeSnippetWrapper"><pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;">Bundle b = <span style="color: blue;">this</span>.getIntent().getExtras();
ArrayList<Category> cats = b.getParcelableArrayList(<span style="color: #006080;">"categories"</span>);
<span style="color: blue;">int</span> index = b.getInt(<span style="color: #006080;">"index"</span>);
</pre><br />
</div>Unknownnoreply@blogger.com11tag:blogger.com,1999:blog-4488365782025760635.post-44693650359678531882010-02-01T11:55:00.001-08:002010-06-18T08:52:45.888-07:00How to add MessageBox in Android?<div id="codeSnippetWrapper">Simple message box with no buttons</div><div><pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;">AlertDialog alertDialog;
alertDialog = <span style="color: blue;">new</span> AlertDialog.Builder(<span style="color: blue;">this</span>).create();
alertDialog.setTitle(<span style="color: #006080;">"Packing List"</span>);
alertDialog.setMessage(<span style="color: #006080;">"Could not find the file."</span>);
alertDialog.show();
</pre><br />
Message box with buttons</div><div id="codeSnippetWrapper"><pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;">AlertDialog deleteAlert = <span style="color: blue;">new</span> AlertDialog.Builder(<span style="color: blue;">this</span>).create();
deleteAlert.setTitle(<span style="color: #006080;">"Delete List"</span>);
deleteAlert.setMessage(<span style="color: #006080;">"Are you sure you want to delete this list?"</span>);
deleteAlert.setButton(<span style="color: #006080;">"Yes"</span>, <span style="color: blue;">new</span> OnClickListener(){
@Override
<span style="color: blue;">public</span> <span style="color: blue;">void</span> onClick(DialogInterface dialog, <span style="color: blue;">int</span> which) {
<span style="color: green;">//...</span>
}
});
deleteAlert.setButton2(<span style="color: #006080;">"No"</span>, <span style="color: blue;">new</span> OnClickListener(){
@Override
<span style="color: blue;">public</span> <span style="color: blue;">void</span> onClick(DialogInterface dialog, <span style="color: blue;">int</span> which) {
<span style="color: green;">//...</span>
}
});
deleteAlert.show();</pre><br />
</div>Unknownnoreply@blogger.com8tag:blogger.com,1999:blog-4488365782025760635.post-33945973042299531552010-01-14T13:53:00.001-08:002010-06-18T08:53:09.377-07:00How to deploy Android application?1. Create icon for your application and add it to the project<br />
<a href="http://lh4.ggpht.com/_ElXg_EOWn5c/S0-VxPIUwlI/AAAAAAAAAdE/smFg5Y9dMJs/s1600-h/image%5B14%5D.png"><img alt="image" border="0" height="208" src="http://lh3.ggpht.com/_ElXg_EOWn5c/S0-Vxe_-5UI/AAAAAAAAAdI/RJMBDtHSKaY/image_thumb%5B4%5D.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="222" /></a> <br />
<a href="http://lh5.ggpht.com/_ElXg_EOWn5c/S0-VxxLmwOI/AAAAAAAAAdM/X_YqhxS9LbM/s1600-h/image%5B24%5D.png"><img alt="image" border="0" height="60" src="http://lh3.ggpht.com/_ElXg_EOWn5c/S0-VyQBOYFI/AAAAAAAAAdQ/mcadd4mxDxg/image_thumb%5B10%5D.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="411" /></a> <br />
2. Export unsigned application<br />
<blockquote><span style="color: #cceedd;">Right click on the project. Click on “Android Tools->Export Unsigned Application Package…”</span></blockquote><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYtNF5NJudTJXp_W5JglH7OVwy-VAq0Ww4x3GCJfFzM-TWxkJqOSwUUn04KSfdPyJJsRrUh2dCA4PtVJnMTLjJdpydo8GPiEe1WHAt-EMzpVLOz3MJahahtNjejeDshe-th-NtH8KqzWo/s1600-h/image%5B25%5D.png"><img alt="image" border="0" height="270" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEbw7pc8tgTs1Jmy2Jn4_DkVFf9j5Q27s4IU8UnKV0kkVUEWDIcSP4syWUm1QQWtZd81eVwZac86b2WfKbgfi9UZBL9rANqLLQ0ThWNtasib5W8Jq_BGCPt9JZ1M1jHEQuxR8pK-lO_48/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="412" /></a> <br />
2. Generate personal certificate by using keytool in java’s jre\bin directory<br />
<a href="http://lh5.ggpht.com/_ElXg_EOWn5c/S0-SS5fKWuI/AAAAAAAAAdg/1Z_7L3PBswA/s1600-h/image%5B26%5D.png"><img alt="image" border="0" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDjpeOSnIdyZbUNBYndGrpBABd00w3eMx-nPgQNjQ6ocBwslv2gN5vSv318bAuRvcTgesqsuvyaGmRN8eqIQPPStvToiSy-bYWT4qUst1eJGfdiQuVKTpU3BOBzsT4OA_XPiLGIEb0lVQ/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="413" /></a> <br />
3. Sign Android application by using jarsigner in jre\bin direcotry<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibiEUl_90S43RySY6XP3UNb2GF8wboOihsxRCu0jPpuoNiBqfq3Rye5XCPaG77_abGboBz340gQTP0t45OT0rJhrGytb3_oFGE66yC5jlhbN7B1sVZqmRbhScQS57oLoHECeIX9Yq7O9c/s1600-h/image%5B28%5D.png"><img alt="image" border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih8GP5162VtcdhLtSKXu7GY05mFSBfDQHHROR28eKP0lvQ6PkOiwhup4ZNL6Lbzv2OWuLTpu7vI4vfGJ5DwOWlbN8BpRhfh_iGxQWGnduC5JBjEl2DqYQsvMELg_tg3-k3hrikcJ89FSU/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="423" /></a> <br />
4. Installation<br />
<blockquote>a) Install application on emulator</blockquote><blockquote><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgGaiK4Q0Kj43jR5Y2_AFXLGy7HlIKM6udpE208-_xb4Ejh363YPtqLKecguwNNA4xZImGBt2zNEImA2DTjPTAHdHH6-KjdSXQX8vgLM9Rc7DE9gS4MLwAC5_-tfZY4W40Ul0TNICfs6Q/s1600-h/image%5B29%5D.png"><img alt="image" border="0" height="65" src="http://lh5.ggpht.com/_ElXg_EOWn5c/S0-SVoonfWI/AAAAAAAAAeE/X3S3hTBIPKo/image_thumb%5B15%5D.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="391" /></a> </blockquote><blockquote>b) Install application on device</blockquote><blockquote>I downloaded ASTRO File Manager and copied the apk file to device. Use File Manager to find the file and tap on it. It prompted me a couple of questions. I have to change my device setting to allow unknown source apps to be installed on my device. </blockquote>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-53198802133340083272010-01-14T13:10:00.001-08:002010-06-18T08:53:23.515-07:00How to obtain Google Map Key for Android Application?This <a href="http://code.google.com/android/add-ons/google-apis/mapkey.html">link</a> will give detailed information on how to get Google Map Key for Android Application. I don’t need to repeat it. Here I just want to give simplified steps for future reference:<br />
1. Get MD5 Fingerprint of the Certificate<br />
<blockquote>a) SDK Debug Certificate</blockquote><blockquote><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMhbqia_oOp1-x6kNPCdrq5eq2LFfg_TGFybodBMRxUlPfkUBFwQ-6_eSGNmgXSQu1oCNiZczgPilbNyCitATsIPUsa0syNBwN3fDhbqDPIMBVtvdSJv6Plr4mDoaPkEZGGjXb3Pzj8kE/s1600-h/image%5B1%5D.png"><img alt="image" border="0" height="64" src="http://lh3.ggpht.com/_ElXg_EOWn5c/S0-IPqVB3LI/AAAAAAAAAeY/w4dCR8U6uT8/image_thumb%5B1%5D.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="406" /></a> </blockquote><blockquote>b) Your Signing Certificate</blockquote><blockquote><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeNBMgmgCllQ4gPtyOriVFpJH7JKd2mhwLPurwz3w0NBpXsZSL60MwEc9KtaIeOFEL91L58-fb4EfgDG0pS3b1z1wmsWN9j-AbfhqENE51FjE3jBoNZWMjihaFpXxSpigCAWwkQm9hiWY/s1600-h/image%5B4%5D.png"><img alt="image" border="0" height="118" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOhbwOz-wjkshwx3lFK0PNjQE3FlY_-fE3avP0RgGMF7RLDZ47xyZBot1s1xB_qt7Bo_RNmRLoJB0mU8yRESfjTRKc4UE_Jx2ZeUXNQ7fGtqbC3VOdt_2hAg10lekbk1oNcIbiuaDJxi8/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="399" /></a> </blockquote>2. Go to this <a href="http://code.google.com/android/maps-api-signup.html">link</a> to sign up for an Android Maps API key<br />
3. Add the key to your application’s AndroidManifest.xml<br />
<div id="codeSnippetWrapper"><pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">com.google.android.maps.MapView</span>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="[your key]"
<span style="color: blue;">/></span></pre><br />
</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-63605842371432345052010-01-14T12:58:00.001-08:002010-06-18T08:54:05.272-07:00MapActivity cannot be resolved to a typeWhen I first working on with MapActivity, I got above error. I kept press Ctrl+Shift+O. However, the type just wouldn’t resolve. Finally I found the answer on the Internet. You need to change the build target to “Google API”<br />
Right click on the project. Go to “Properties”. Change the “Build Target” from “Android 1.x to Google APIs 1.x” <br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjroTHBnPnW9uGHop6yOcc-wHYWbjEMWRklNH60YQMUUbgfdJeaRviWLDJliOnBVkJf8wZlk1HkekTw9RPAupvFeY92g8uiO94mafqnZUVLfueoLySa9AyeJbM7CC_-9Ds_sdDo6-9AVc0/s1600-h/image%5B1%5D.png"><img alt="image" border="0" height="326" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVVbu367S7HLOjbohmGT-iy9qEKnnO7KwTRitmO49ozwwWLde8tppQjS4aydPYAaC0m39k6euvLrA0DK6ZUVsKasQod365NCCYLpJ57C8iCTOkBaG-51U6ZkxmYsCotf7uLqCWUWPV0uY/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="372" /></a>Unknownnoreply@blogger.com26tag:blogger.com,1999:blog-4488365782025760635.post-27322008285798718272010-01-14T07:23:00.000-08:002011-08-30T08:24:26.127-07:00Read, Write and Parse XML file in Android1. Read and Parse Xml file<br>The sample XML file looks like the following:<br> <div> <div id="codeSnippetWrapper"> <div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">packingList</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"><</span><span style="color: #800000">category</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="test"</span><span style="color: #0000ff">></span><br> <span style="color: #0000ff"></</span><span style="color: #800000">category</span><span style="color: #0000ff">></span><br><span style="color: #0000ff"><</span><span style="color: #800000">packingList</span><span style="color: #0000ff">></span></pre><br></div><br>The following code shows you how to read and parse the file</div></div>
<div></div>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">ArrayList<Category> categories;<br>XmlPullParser parser = Xml.newPullParser();<br><span style="color: #0000ff">try</span> {<br> FileInputStream fIn = openFileInput(FILE_NAME); <br> InputStreamReader isr = <span style="color: #0000ff">new</span> InputStreamReader(fIn);<br> <br> <span style="color: #008000">// auto-detect the encoding from the stream</span><br> parser.setInput(isr);<br> <span style="color: #0000ff">int</span> eventType = parser.getEventType();<br> Category currentCategory = null;<br> <span style="color: #0000ff">boolean</span> done = false;<br> <span style="color: #0000ff">while</span> (eventType != XmlPullParser.END_DOCUMENT && !done){<br> String name = null;<br> <span style="color: #0000ff">switch</span> (eventType){<br> <span style="color: #0000ff">case</span> XmlPullParser.START_DOCUMENT:<br> <span style="color: #0000ff">break</span>;<br> <span style="color: #0000ff">case</span> XmlPullParser.START_TAG:<br> name = parser.getName();<br> <span style="color: #0000ff">if</span> (name.equalsIgnoreCase(<span style="color: #006080">"packingList"</span>)){<br> categories = <span style="color: #0000ff">new</span> ArrayList<Category>();<br> } <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (categories != null){<br> <span style="color: #0000ff">if</span> (name.equalsIgnoreCase(<span style="color: #006080">"category"</span>))<br> currentCategory = <span style="color: #0000ff">new</span> Category(parser.getAttributeValue(0)); <br> }<br> <span style="color: #0000ff">break</span>;<br> <span style="color: #0000ff">case</span> XmlPullParser.END_TAG:<br> name = parser.getName();<br> <span style="color: #0000ff">if</span> (name.equalsIgnoreCase(<span style="color: #006080">"category"</span>) && <br> currentCategory != null){<br> categories.add(0, currentCategory);<br> } <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (name.equalsIgnoreCase(<span style="color: #006080">"packingList"</span>)){<br> done = true;<br> }<br> <span style="color: #0000ff">break</span>;<br> }<br> eventType = parser.next();<br> }<br>} <span style="color: #0000ff">catch</span> (FileNotFoundException e) {<br> <span style="color: #008000">// TODO</span><br>} <span style="color: #0000ff">catch</span> (IOException e) {<br> <span style="color: #008000">// TODO</span><br>} <span style="color: #0000ff">catch</span> (Exception e){<br> <span style="color: #008000">// TODO</span><br>}</pre><br></div><br></div>
<div>2. Write to file</div>
<div> </div>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">try</span> {<br> FileOutputStream fOut = openFileOutput(FILE_NAME, MODE_WORLD_READABLE); <br> OutputStreamWriter osw = <span style="color: #0000ff">new</span> OutputStreamWriter(fOut); <br> String fileContent = …; <span style="color: #008000">//build file content</span><br> osw.write(fileContent ); <br> osw.flush(); <br> osw.close();<br> <br>} <span style="color: #0000ff">catch</span> (FileNotFoundException e) {<br>…<br>}</pre><br></div><br></div>
<div> </div> Unknownnoreply@blogger.com12tag:blogger.com,1999:blog-4488365782025760635.post-31370581843421218462010-01-12T09:36:00.001-08:002010-06-18T08:54:16.184-07:00How to kill an application running in Android Emulator?Since I am not a Java programmer, there is a learning curve using Eclipse. I am getting used it. But sometimes I have to search the Internet to find answers for really simple question like this one. And here is how.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIpJ3Mvn41sfXEKyx5hTUcGzKb_h6c6sVrAQq6-rIJn_lIzcbUWgj0Ay0icLXhZTs0J-DTwp_-SO6KmmClSODErDy17JKOtcxcVT2Titqs0ISXbTTCeqTrB2lb3b91MKynLOTQ_MMUq5A/s1600-h/image%5B1%5D.png"><img alt="image" border="0" height="134" src="http://lh3.ggpht.com/_ElXg_EOWn5c/S0yzEdrl4XI/AAAAAAAAAfM/FtIkLMAX4II/image_thumb%5B1%5D.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="418" /></a> <br />
1. Click on “DDMS”<br />
2. Select the application you want to kill<br />
3. Click on “Stop”Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-4488365782025760635.post-53030639992154865112010-01-12T09:26:00.001-08:002010-06-18T08:54:26.406-07:00Android 2.0 UpdateTo get Android SDK 2.0 update, go to “Windows->Android SDK Manager” to download the new update.<br />
After download the update, I got the following message when try to open my existing application<br />
<a href="http://lh5.ggpht.com/_ElXg_EOWn5c/S0yw2vBCVOI/AAAAAAAAAb0/KaUlNa9_-Wc/s1600-h/image%5B2%5D.png"><img alt="image" border="0" height="91" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUbqzh14qLtqRoWOMRDytuDl-7u9pCjq4-Ks6LyltgWS9ezcKRYhfRUNcIpUgS1s6IDycGoCB3aYW_AUT_S5pP0sOhLNmQmtGWLUEsGkOGcM1KRAWB5IqTCF7wL1oRCPTMI_2IOx8RFlM/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="244" /></a> <br />
I went to “Help->Software Updates…” and installed the developer tools in below screen shot.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtjxgFjrS5slg-r3P2qa0sTzVaRsIIP0cBKefAKvwgJlQ-wUKdwcq4gVuXG4z_izh5dYczuNBGI8kmoCp1vzBOf-GTkWGA8uEZkcbyg3sHxitv_zYtb-pHKt6CQflLSRWQgcan4wEAViA/s1600-h/image%5B5%5D.png"><img alt="image" border="0" height="139" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjX2gmhyum4_iw2ExdqrFNVt3_1zhwHiUglIhMoLQ-MAJ8IjJ2MBO-Bk14biFNP_rGX_-xzmH1RqLjOhyphenhyphenWIrbIeOVj8cqEOCofxOQEzB4HwLeTYy2MLjWILbcnbCatjapx3Xx7i2ayXLHo/?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="244" /></a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-85114803661337290402010-01-12T08:32:00.001-08:002010-06-18T08:54:40.050-07:00Issues with running my first “Hello Android” applicationSoon after I have the environment setup, I created my first Android application “Hello Android”. The app is sure simple, but I still run into some issues when running it. <br />
The first one is “HelloAndroidConversion to Delvik format failed with error 1” (see screen shot below)<br />
<a href="http://lh5.ggpht.com/_ElXg_EOWn5c/S0ykB4-FcAI/AAAAAAAAAbg/_94cgBo7bwY/s1600-h/image%5B2%5D.png"><img alt="image" border="0" height="37" src="http://lh4.ggpht.com/_ElXg_EOWn5c/S0ykCI5z6eI/AAAAAAAAAbk/rXVqDIy5R1w/image_thumb.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="244" /></a><br />
I am not a Java programmer and I have no idea what the issue is. After searching the answer on the Internet, I found the solution. That is go to “Project-Clean…” in Eclipse.<br />
Then I received error “Could not find HelloAndroid.apk!”<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTBnrp6QsHdEPCF5INpFVPd-NPezlUH-vdxo_2uu-lTRjydoXgy1slo-gYy43E0Nlx0RXeuFeoDYQx2k1luqviP2nA1i05jLKy6cWU9LNx50PiYorsGsAA7y9yWqVxTRsbvlXIaL3YoV0/s1600-h/image%5B5%5D.png"><img alt="image" border="0" height="30" src="http://lh6.ggpht.com/_ElXg_EOWn5c/S0ykC1ruV0I/AAAAAAAAAbs/ekEFYG8yarY/image_thumb%5B1%5D.png?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="244" /></a> <br />
It turned out to be the path I added to the system variable. I added “C:\Android\GlassFish-Tools-Bundle-For-Eclipse-1.1\jre\bin” to Path in windows system environment variable. I removed “\bin” and do “Project->Clean…” again. The issue is gone.<br />
The emulator kept shutting down even after I passed these two issues. I had to start the emulator first. Even so, it failed to run it the first time. But it worked the second time and after. Strange!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-4488365782025760635.post-70578078054784651762010-01-07T18:23:00.001-08:002010-06-18T08:38:08.360-07:00Android Development Environment Setup1. Download Android SDK 1.6<br />
2. Download GlassFish tool bundle for Eclipse 1.1<br />
<blockquote><span style="color: #cceedd;">Don’t ask me why GlassFish. That is the first Eclipse tool I found, so I just installed it.</span></blockquote>3. Install Android plug-in in Eclipse<br />
<blockquote>If you got the “No repository found at <a href="https://dl-ssl.google.com/android/eclipse/">https://dl-ssl.google.com/android/eclipse/</a>” error when using the URL on Andorid web site which is the checked one in the following screen shot, use the second URL on the screen instead.</blockquote><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWlTykazV8mQLv4mjCDS5c_yL-mbetus31nXIixLuJazc3blxJ-E2fh8XrzHrRl-FD21KzEpGDxWuEH8Wmqjr8pbFwNnvhUxl4DkwkBURooB8N_5dAUycbOTadzMiCugxjDZNqEYDr_lw/s1600-h/image%5B2%5D.png"><img alt="image" border="0" height="135" src="http://lh3.ggpht.com/_ElXg_EOWn5c/S0aXHg4isoI/AAAAAAAAAbU/ud_6YDg8byY/image_thumb.png?imgmax=800" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="244" /></a> <br />
4. Install AVD(Android Virtual Device)<br />
<blockquote><span style="color: #cceedd;">\[Android sdk folder]\tools\android create avd –-target 2 –-name my_avd</span></blockquote><blockquote><span style="color: #cceedd;">Don’t forget to </span>add “[Eclipse folder]\jre” to the PATH in Environment Variables</blockquote>5. Set up Android SDK location in Eclipse. Go to Windows->Preferences<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMFUt1_B5lhOtrE9MO2V_iyppkmRmNnM1wEs2Zk0vCKQ28DKB_j_tHvK3Zxl5toAQ2ocANonVzRJgs-UyetLIsBbzgpg9hORZ8fqETyzMdaoIG4-6R5TvhgUBcIO1_v_63rWPOVBU-TOQ/s1600-h/image%5B8%5D.png"><img alt="image" border="0" height="89" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPFTRzo2pbiUDZjFJI2HyuSYQNMKXfxgahuWhRmm2xq5j_67aPqiAEPeCCJbi7D9kJlHptgLEgerMgLMoRZC55nNQqKuvgVQ9KEd_3_iiKnrSntUscvFTf-cX1EjF4k3Fvz5FIJPE2BUA/?imgmax=800" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="244" /></a>Unknownnoreply@blogger.com1