tag:blogger.com,1999:blog-68158667127480421622024-02-18T21:28:55.705-08:00Android development tutorial for beginners Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-6815866712748042162.post-39454992538805665092013-06-01T05:17:00.004-07:002013-06-01T05:17:56.865-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Android Pickers(Date and Time Pickers)</b></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">In Android, you can use “<a href="http://developer.android.com/reference/android/widget/DatePicker.html"><span class="s1"><span style="color: blue;">android.widget.DatePicker</span></span></a>” class to render a date picker component to select day, month and year in a pre-defined user interface and you can use “<a href="http://developer.android.com/reference/android/widget/TimePicker.html"><span class="s1"><span style="color: blue;">android.widget.TimePicker</span></span></a>” class to render a time picker component to select hour and minute in a pre-defined user interface.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year). Using these pickers helps ensure that your users can pick a time or date that is valid, formatted correctly, and adjusted to the user's locale.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Google recommend that you use <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> to host each time or date picker. The <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> manages the dialog lifecycle for you and allows you to display the pickers in different layout configurations, such as in a basic dialog on handsets or as an embedded part of the layout on large screens.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Although <a href="http://developer.android.com/reference/android/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> was first added to the platform in Android 3.0 (API level 11), if your app supports versions of Android older than 3.0—even as low as Android 1.6—you can use the <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> class that's available in the <span style="color: blue;"><a href="http://developer.android.com/tools/extras/support-library.html"><span class="s2"><span style="color: blue;">support library</span></span></a> </span>for backward compatibility.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Creating a Date Picker</span></b><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">To display a <a href="http://developer.android.com/reference/android/app/DatePickerDialog.html"><span class="s1"><span style="color: blue;">DatePickerDialog</span></span></a> using <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a>, you need to define a fragment class that extends <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> and return a <a href="http://developer.android.com/reference/android/app/DatePickerDialog.html"><span class="s1"><span style="color: blue;">DatePickerDialog</span></span></a> from the fragment's <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html#onCreateDialog(android.os.Bundle)"><span class="s1"><span style="color: blue;">onCreateDialog()</span></span></a> method.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Note:</b> If your app supports versions of Android older than 3.0, be sure you've set up your Android project with the support library as described in <a href="http://developer.android.com/tools/extras/support-library.html#SettingUp"><span class="s2"><span style="color: blue;">Setting Up a Project to Use a Library</span></span></a>.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p2">
<b><span style="font-family: Arial, Helvetica, sans-serif;">Extending DialogFragment for a date picker</span></b></div>
<div class="p2">
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">To define a <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> for a <a href="http://developer.android.com/reference/android/app/DatePickerDialog.html"><span class="s1"><span style="color: blue;">DatePickerDialog</span></span></a>, you must:</span></div>
<ul class="ul1">
<li class="li3"><span style="font-family: Arial, Helvetica, sans-serif;">Define the <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html#onCreateDialog(android.os.Bundle)"><span class="s1"><span style="color: blue;">onCreateDialog()</span></span></a> method to return an instance of <a href="http://developer.android.com/reference/android/app/DatePickerDialog.html"><span class="s1"><span style="color: blue;">DatePickerDialog</span></span></a></span></li>
<li class="li3"><span style="font-family: Arial, Helvetica, sans-serif;">Implement the <a href="http://developer.android.com/reference/android/app/DatePickerDialog.OnDateSetListener.html"><span class="s1"><span style="color: blue;">DatePickerDialog.OnDateSetListener</span></span></a> interface to receive a callback when the user sets the date.</span></li>
</ul>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Here's an example:</span></div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>package</b></span><span style="color: black;">
com.learnsimply.datetimepickerexample;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
java.util.Calendar;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.DatePickerDialog;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Dialog;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.support.v4.app.DialogFragment;</span></span></span></div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #7f0055;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><b>import</b></span></span></span><span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
android.widget.DatePicker;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
DatePickerFragment </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
DialogFragment </span><span style="color: #7f0055;"><b>implements</b></span><span style="color: black;">
DatePickerDialog.OnDateSetListener{</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
Dialog onCreateDialog(Bundle savedInstanceState) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Use the current date as the
default date in the picker</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>final</b></span><span style="color: black;">
Calendar c = Calendar.</span><span style="color: black;"><i>getInstance</i></span><span style="color: black;">();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
year = c.get(Calendar.</span><span style="color: #0000c0;"><i>YEAR</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
month = c.get(Calendar.</span><span style="color: #0000c0;"><i>MONTH</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
day = c.get(Calendar.</span><span style="color: #0000c0;"><i>DAY_OF_MONTH</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Create a new instance of
DatePickerDialog and return it</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>return</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
DatePickerDialog(getActivity(), </span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,
year, month, day);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onDateSet(DatePicker view, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
year, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
month, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
day) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Do something with the date
chosen by the user</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">}</span></span></span></div>
<div class="p1">
</div>
<div style="margin-bottom: 0cm;">
<br /></div>
</div>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Now all you need is an event that adds an instance of this fragment to your activity.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif;">Showing the date picker</span></b></div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;">Once you've defined a <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> like the one shown above, you can display the date picker by creating an instance of the <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> and calling <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html#show(android.support.v4.app.FragmentManager,%20java.lang.String)"><span class="s1"><span style="color: blue;">show()</span></span></a>.</span></div>
<div class="p1">
</div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;">For example, here's a button that, when clicked, calls a method to show the dialog:</span></div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p2">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnChangeDate"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #2a00ff;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Change
Date"</u></i></span></span></span></div>
<div class="p2">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #7f007f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">android:onClick</span></span></span><span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">=</span></span></span><span style="color: #2a00ff;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><i>"showDatePickerDialog"</i></span></span></span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">When the user clicks this button, the system calls the following method:</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
showDatePickerDialog(View v) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
DialogFragment newFragment = </span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
DatePickerFragment();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
newFragment.show(getSupportFragmentManager(), </span><span style="color: #2a00ff;">"datePicker"</span><span style="color: black;">);</span></span></span></div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: x-small;"> }</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: x-small;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Creating a Time Picker</span></b></div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">To display a <a href="http://developer.android.com/reference/android/app/TimePickerDialog.html"><span class="s1"><span style="color: blue;">TimePickerDialog</span></span></a> using <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a>, you need to define a fragment class that extends <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> and return a <a href="http://developer.android.com/reference/android/app/TimePickerDialog.html"><span class="s1"><span style="color: blue;">TimePickerDialog</span></span></a> from the fragment's <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html#onCreateDialog(android.os.Bundle)"><span class="s1"><span style="color: blue;">onCreateDialog()</span></span></a> method.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Note:</b> If your app supports versions of Android older than 3.0, be sure you've set up your Android project with the support library as described in <a href="http://developer.android.com/tools/extras/support-library.html#SettingUp"><span class="s2"><span style="color: blue;">Setting Up a Project to Use a Library</span></span></a>.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p2">
<b><span style="font-family: Arial, Helvetica, sans-serif;">Extending DialogFragment for a time picker</span></b></div>
<div class="p2">
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">To define a <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> for a <a href="http://developer.android.com/reference/android/app/TimePickerDialog.html"><span class="s1"><span style="color: blue;">TimePickerDialog</span></span></a>, you must:</span></div>
<ul class="ul1">
<li class="li3"><span style="font-family: Arial, Helvetica, sans-serif;">Define the <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html#onCreateDialog(android.os.Bundle)"><span class="s1"><span style="color: blue;">onCreateDialog()</span></span></a> method to return an instance of <a href="http://developer.android.com/reference/android/app/TimePickerDialog.html"><span class="s1"><span style="color: blue;">TimePickerDialog</span></span></a></span></li>
<li class="li3"><span style="font-family: Arial, Helvetica, sans-serif;">Implement the <a href="http://developer.android.com/reference/android/app/TimePickerDialog.OnTimeSetListener.html"><span class="s1"><span style="color: blue;">TimePickerDialog.OnTimeSetListener</span></span></a> interface to receive a callback when the user sets the time.</span></li>
</ul>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Here's an example:</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>package</b></span><span style="color: black;">
com.learnsimply.datetimepickerexample;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
java.util.Calendar;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Dialog;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.TimePickerDialog;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.support.v4.app.DialogFragment;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.text.format.DateFormat;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.TextView;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.TimePicker;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
TimePickerFragment </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
DialogFragment </span><span style="color: #7f0055;"><b>implements</b></span><span style="color: black;">
TimePickerDialog.OnTimeSetListener{</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> TextView
</span><span style="color: #0000c0;">txtTime</span><span style="color: black;">;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
TimePickerFragment(TextView txtTime) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">.</span><span style="color: #0000c0;">txtTime</span><span style="color: black;">
= txtTime;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> }</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
Dialog onCreateDialog(Bundle savedInstanceState) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Use the current time as the
default values for the picker</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>final</b></span><span style="color: black;">
Calendar c = Calendar.</span><span style="color: black;"><i>getInstance</i></span><span style="color: black;">();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
hour = c.get(Calendar.</span><span style="color: #0000c0;"><i>HOUR_OF_DAY</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
minute = c.get(Calendar.</span><span style="color: #0000c0;"><i>MINUTE</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Create a new instance of
TimePickerDialog and return it</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>return</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
TimePickerDialog(getActivity(), </span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,
hour, minute,</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
DateFormat.<i>is24HourFormat</i>(getActivity()));</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onTimeSet(TimePicker view, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
hourOfDay, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
minute) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Do something with the time
chosen by the user</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Now all you need is an event that adds an instance of this fragment to your activity.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif;">Showing the time picker</span></b></div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;">Once you've defined a <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> like the one shown above, you can display the time picker by creating an instance of the <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s1"><span style="color: blue;">DialogFragment</span></span></a> and calling <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html#show(android.support.v4.app.FragmentManager,%20java.lang.String)"><span class="s1"><span style="color: blue;">show()</span></span></a>.</span></div>
<div class="p1">
</div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;">For example, here's a button that, when clicked, calls a method to show the dialog:</span></div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p2">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnChangeTime"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Change
Time"</u></i></span></span></span></div>
<div class="p2">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:onClick</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"showTimePickerDialog"
</i></span><span style="color: teal;">/></span></span></span></div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">When the user clicks this button, the system calls the following method:</span></div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
showTimePickerDialog(View v) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
DialogFragment newFragment = </span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
TimePickerFragment(</span><span style="color: #0000c0;">txtDisplayTime</span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
newFragment.show(getSupportFragmentManager(), </span><span style="color: #2a00ff;">"timePicker"</span><span style="color: black;">);</span></span></span></div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> }</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Run the application</b></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUqqi-NgvvVKOMTkCp3V2_28eF0US0Xk53jCcnjYGX0WPc7ZOCzy_ZD3vB4tQqvDKOZ9Gv6qsJKLX0VSN3LgArYGiNa7peL005_52sZlU3x9t0uJISEdszQ3-IoWrCRbCVJwBuwYjsCSJc/s1600/date.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUqqi-NgvvVKOMTkCp3V2_28eF0US0Xk53jCcnjYGX0WPc7ZOCzy_ZD3vB4tQqvDKOZ9Gv6qsJKLX0VSN3LgArYGiNa7peL005_52sZlU3x9t0uJISEdszQ3-IoWrCRbCVJwBuwYjsCSJc/s640/date.png" width="384" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTka1xqyY5885c3ktxGA7pEUqcSj3mGesNCTSVQN3j-S_8KLiPSUfHYuUTBgI9ibq8OEVTUGEsR0kuFWLrpNtRnKPfgyV_13db-wKQ_Pqv5I_IJQBwStM7JAFTw8joTn3mktuG3gwHqlY3/s1600/date_picker.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTka1xqyY5885c3ktxGA7pEUqcSj3mGesNCTSVQN3j-S_8KLiPSUfHYuUTBgI9ibq8OEVTUGEsR0kuFWLrpNtRnKPfgyV_13db-wKQ_Pqv5I_IJQBwStM7JAFTw8joTn3mktuG3gwHqlY3/s640/date_picker.png" width="384" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsvQqrEWdNOHh9tE4t4FO11Q_X63uEMNsdWPoaE5aRzPHaRWQaF4OZijP054lfNOnZxgMkS9YqX5MQW2ywHO0uB64r8UsIuneyUBsxfok4NjfvU1agu0MjSI8bJTZeffkePBIrKKDpMqBc/s1600/time_picker.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsvQqrEWdNOHh9tE4t4FO11Q_X63uEMNsdWPoaE5aRzPHaRWQaF4OZijP054lfNOnZxgMkS9YqX5MQW2ywHO0uB64r8UsIuneyUBsxfok4NjfvU1agu0MjSI8bJTZeffkePBIrKKDpMqBc/s640/time_picker.png" width="384" /></a></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><span class="s1"><b>Note:</b> In this sample i use </span><span class="s2">android.support.v4 and FragmentActivity because <a href="http://developer.android.com/reference/android/app/DialogFragment.html"><span class="s3"><span style="color: blue;">DialogFragment</span></span></a></span> was first added to the platform in Android 3.0 (API level 11), if your app supports versions of Android older than 3.0—even as low as Android 1.6—you can use the <a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html"><span class="s4"><span style="color: blue;">DialogFragment</span></span></a> class that's available in the <a href="http://developer.android.com/tools/extras/support-library.html"><span class="s4"><span style="color: blue;">support library</span></span></a><span class="s4"> </span>for backward compatibility.</span></div>
<div class="p1">
<span style="color: #3c3c3c; font-family: Arial, sans-serif; font-size: medium; line-height: 36px;"><br /></span></div>
<div class="p1">
<span style="color: #3c3c3c; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 36px;"><b>Download Source Code</b></span><span style="color: #3c3c3c; font-family: Arial, sans-serif; font-size: medium; line-height: 36px;"> </span><span style="color: #3c3c3c; line-height: 36px;"><span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoX19KcmlXNnp4dTg/edit" target="_blank">DateTimePicker.zip</a></span></span></div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com1tag:blogger.com,1999:blog-6815866712748042162.post-31206598939519273732013-05-31T06:13:00.002-07:002013-05-31T06:13:13.629-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Android Spinner</span></b><br />
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; line-height: 21px;">In Android, you can use “</span><a href="http://developer.android.com/reference/android/widget/Spinner.html" style="background-color: white; line-height: 21px;" target="_blank"><span style="color: blue;">android.widget.Spinner</span></a><span style="background-color: white; line-height: 21px;">” class to render a dropdown box selection list.</span></span><br />
<span style="background-color: #f9f9f9; line-height: 19px;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span>
<span style="background-color: #f9f9f9; line-height: 19px;"><span style="font-family: Arial, Helvetica, sans-serif;">Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.</span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: #f9f9f9; line-height: 19px;"><br /></span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: #f9f9f9; line-height: 19px;">You can add a spinner to your layout with the </span><code style="background-color: #f9f9f9; line-height: 14px;"><a href="http://developer.android.com/reference/android/widget/Spinner.html" style="text-decoration: none;"><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Spinner</span></a></code><span style="background-color: #f9f9f9; line-height: 19px;"> object. You should usually do so in your XML layout with a </span><code style="background-color: #f9f9f9; line-height: 14px;"><Spinner></code><span style="background-color: #f9f9f9; line-height: 19px;"> element.</span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: #f9f9f9; line-height: 19px;"><br /></span></span>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><i><</i></span><span style="color: #3f7f7f;"><i>Spinner</i></span></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/spinner"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"fill_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #7f007f; font-family: Monaco, monospace; font-size: 11pt;">android:layout_height</span><span style="color: black; font-family: Monaco, monospace; font-size: 11pt;">=</span><span style="color: #2a00ff; font-family: Monaco, monospace; font-size: 11pt;"><i>"wrap_content"</i></span><span style="font-family: Monaco, monospace; font-size: 11pt;">
</span><span style="color: teal; font-family: Monaco, monospace; font-size: 11pt;">/></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal; font-family: Monaco, monospace; font-size: 11pt;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Here i implements <span style="color: blue;">OnItemSelectedListener</span> geting the <span style="color: blue;">Spinner</span> selected item. I also set <span style="color: blue;">Spinner</span> selected item to a text view (code: <span style="color: blue;">selection.setText(items[position]</span>)<b>;</b></span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>1.Spinner</b></span></div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><i><?</i></span><span style="color: #3f7f7f;"><i>xml</i></span><span style="color: teal;"><i>
</i></span><span style="color: #7f007f;"><i>version</i></span><span style="color: black;"><i>=</i></span><span style="color: #2a00ff;"><i>"1.0"</i></span><span style="color: teal;"><i>
</i></span><span style="color: #7f007f;"><i>encoding</i></span><span style="color: black;"><i>=</i></span><span style="color: #2a00ff;"><i>"utf-8"</i></span><span style="color: teal;"><i>?></i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">LinearLayout</span>
<span style="color: #7f007f;">xmlns:android</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"fill_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"fill_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:orientation</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"vertical"</i></span>
<span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">TextView</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/selection"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"fill_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Spinner</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/spinner"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"fill_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:drawSelectorOnTop</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"true"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>2.Code</b></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><i><b>package</b></i></span><span style="color: black;"><i>
com.learnsimply.spinnerexample;</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Activity;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.view.View;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.AdapterView;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.AdapterView.OnItemSelectedListener;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.ArrayAdapter;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Spinner;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.TextView;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
Activity </span><span style="color: #7f0055;"><b>implements</b></span><span style="color: black;">
OnItemSelectedListener{</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> TextView
</span><span style="color: #0000c0;">selection</span><span style="color: black;">;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
Spinner </span><span style="color: #0000c0;">spin</span><span style="color: black;">;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
String[] </span><span style="color: #0000c0;">items</span><span style="color: black;">
= { </span><span style="color: #2a00ff;">"India"</span><span style="color: black;">,
</span><span style="color: #2a00ff;">"USA"</span><span style="color: black;">,
</span><span style="color: #2a00ff;">"England"</span><span style="color: black;">,
</span><span style="color: #2a00ff;">"australia"</span><span style="color: black;">,
</span><span style="color: #2a00ff;">"japan"</span><span style="color: black;">,</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #2a00ff;">"china"</span><span style="color: black;">,
</span><span style="color: #2a00ff;">"korea"</span><span style="color: black;">
};</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f5fbf;">/** Called when the activity is first
created. */</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onCreate(savedInstanceState);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
setContentView(R.layout.</span><span style="color: #0000c0;"><i>activity_main</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #0000c0;">selection</span><span style="color: black;">
= (TextView) findViewById(R.id.</span><span style="color: #0000c0;"><i>selection</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
Spinner spin = (Spinner) findViewById(R.id.</span><span style="color: #0000c0;"><i>spinner</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
spin.setOnItemSelectedListener(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
ArrayAdapter<String> aa = </span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
ArrayAdapter<String>(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
android.R.layout.</span><span style="color: #0000c0;"><i>simple_spinner_item</i></span><span style="color: black;">,
</span><span style="color: #0000c0;">items</span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
spin.setAdapter(aa);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onItemSelected(AdapterView<?> parent, View v, </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
position,</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>long</b></span><span style="color: black;">
id) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// </span><span style="color: #7f9fbf;"><b>TODO</b></span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #0000c0;">selection</span><span style="color: black;">.setText(</span><span style="color: #0000c0;">items</span><span style="color: black;">[position]);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onNothingSelected(AdapterView<?> arg0) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// </span><span style="color: #7f9fbf;"><b>TODO</b></span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #0000c0;">selection</span><span style="color: black;">.setText(</span><span style="color: #2a00ff;">""</span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> }</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Run the code</b></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgROoeTxVQSyTzPXn1d0kv3eA2tuVB3rAGbCbXrqPYm_D3OIXE76zVPd7CjIAa2_bZOIjugBaUv3ZFhMbJ3szLeqdobHwq-dLDXuYjaAScxYTZFXlRv9U21GS3Eun0LUuEMW3BgMbOz94qn/s1600/spinner.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: blue;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgROoeTxVQSyTzPXn1d0kv3eA2tuVB3rAGbCbXrqPYm_D3OIXE76zVPd7CjIAa2_bZOIjugBaUv3ZFhMbJ3szLeqdobHwq-dLDXuYjaAScxYTZFXlRv9U21GS3Eun0LUuEMW3BgMbOz94qn/s640/spinner.png" width="384" /></span></a></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<h4 style="background-color: white; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px;">Download Source Code </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif; font-weight: normal;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoMVhETTVPYmlnUkk/edit" target="_blank">SpinnerExample.zip</a></span></h4>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-65156385978002491082013-05-31T05:20:00.003-07:002013-05-31T05:50:23.073-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Android Toggle Buttons</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">A toggle button allows the user to change a setting between two states.</span></div>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">You can add a basic toggle button to your layout with the <a href="http://developer.android.com/reference/android/widget/ToggleButton.html"><span class="s1" style="color: blue;">ToggleButton</span></a> object. Android 4.0 (API level 14) introduces another kind of toggle button called a switch that provides a slider control, which you can add with a <a href="http://developer.android.com/reference/android/widget/Switch.html"><span class="s1"><span style="color: blue;">Switch</span></span></a> object.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">The <a href="http://developer.android.com/reference/android/widget/ToggleButton.html"><span class="s1"><span style="color: blue;">ToggleButton</span></span></a> and <a href="http://developer.android.com/reference/android/widget/Switch.html"><span class="s1"><span style="color: blue;">Switch</span></span></a> controls are subclasses of <a href="http://developer.android.com/reference/android/widget/CompoundButton.html"><span class="s1"><span style="color: blue;">CompoundButton</span></span></a> and function in the same manner, so you can implement their behavior the same way.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<h3>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Toggle Button Click Event</span></h3>
<div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">When the user selects a <a href="http://developer.android.com/reference/android/widget/ToggleButton.html"><span class="s1" style="color: blue;">ToggleButton</span></a> and <a href="http://developer.android.com/reference/android/widget/Switch.html"><span class="s1" style="color: blue;">Switch</span></a>, the object receives an on-click event.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">To define the click event handler, add the <a href="http://developer.android.com/reference/android/R.attr.html#onClick"><span class="s1" style="color: blue;">android:onClick</span></a> attribute to the <span class="s2"><ToggleButton></span> or <span class="s2"><Switch></span>element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The <a href="http://developer.android.com/reference/android/app/Activity.html"><span class="s1" style="background-color: white;"><span style="color: blue;">Activity</span></span></a> hosting the layout must then implement the corresponding method.</span></div>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br />
</span></div>
<div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Within the <a href="http://developer.android.com/reference/android/app/Activity.html"><span class="s1"><span style="color: blue;">Activity</span></span></a> that hosts this layout, the following method handles the click event:</span></div>
</div>
<div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><i><span style="background: #ffffff;"><</span></i></span><span style="color: #3f7f7f;"><i><span style="background: #ffffff;">ToggleButton</span></i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/togglebutton"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:onClick</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"onToggleClicked"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:textOff</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"Sound off"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #7f007f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">android:textOn</span></span></span><span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">=</span></span></span><span style="color: #2a00ff;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><i>"Sound on"</i></span></span></span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">/></span></span></span><br />
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;">Within the Activity that hosts this layout, the following method handles the click event:</span><br />
<br />
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><b>public</b></span></span></span><span style="color: black;"><span style="font-family: Arial, sans-serif;"><span style="font-size: medium;">
</span></span></span><span style="color: #7f0055;"><span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><b>void</b></span></span></span><span style="color: black;"><span style="font-family: Arial, sans-serif;"><span style="font-size: medium;">
onToggleClicked(View view) {</span></span></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Is the toggle on?</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>boolean</b></span><span style="color: black;">
on = </span><span style="color: black;"><u>((ToggleButton)
view)</u></span><span style="color: black;">.isChecked();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, sans-serif;"><span style="font-size: medium;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>if</b></span><span style="color: black;">
(on) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Enable Sound</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><span style="color: black;">
} </span><span style="color: #7f0055;"><b>else</b></span><span style="color: black;">
{</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Disable Sound</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, sans-serif;"><span style="font-size: medium;">
}</span></span></span></div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: medium;"><br /></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">The method you declare in the <a href="http://developer.android.com/reference/android/R.attr.html#onClick"><span class="s1"><span style="color: blue;">android:onClick</span></span></a> attribute must have a signature exactly as shown above. Specifically, the method must:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">In this tutorial, we show you how to use XML to create two toggle buttons and a normal button, when user click on the normal button, it will display the current state of both toggle buttons.</span></div>
<div class="p1">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px;"><br /></span></div>
<div class="p1">
<span style="background-color: white; font-size: 24px; line-height: 36px;"><b><span style="font-family: Arial, Helvetica, sans-serif;">2. ToggleButton</span></b></span></div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">LinearLayout</span>
<span style="color: #7f007f;">xmlns:android</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">tools:context</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:orientation</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"vertical"</i></span>
<span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">ToggleButton</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/toggleButton1"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"ToggleButton"</u></i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">ToggleButton</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/toggleButton2"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"ToggleButton"</u></i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnDisplay"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Display"</u></i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"></</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">LinearLayout</span></span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; line-height: 36px;"><b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">3. Code </span></b></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><i><b>package</b></i></span><span style="color: black;"><i>
com.learnsimply.toggelbuttonexample;</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Activity;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.view.View;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.view.View.OnClickListener;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Button;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Toast;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.ToggleButton;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
Activity {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>private</b></span><span style="color: black;">
ToggleButton </span><span style="color: #0000c0;">toggleButton1</span><span style="color: black;">,
</span><span style="color: #0000c0;">toggleButton2</span><span style="color: black;">;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>private</b></span><span style="color: black;">
Button </span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">;</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>protected</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onCreate(savedInstanceState);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> setContentView(R.layout.</span><span style="color: #0000c0;"><i>activity_main</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> InitializeButtonClick();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> }</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
InitializeButtonClick() {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">toggleButton1</span><span style="color: black;">
= (ToggleButton) findViewById(R.id.</span><span style="color: #0000c0;"><i>toggleButton1</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">toggleButton2</span><span style="color: black;">
= (ToggleButton) findViewById(R.id.</span><span style="color: #0000c0;"><i>toggleButton2</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">
= (Button) findViewById(R.id.</span><span style="color: #0000c0;"><i>btnDisplay</i></span><span style="color: black;">);</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">.setOnClickListener(</span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
OnClickListener() {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onClick(View v) {</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
StringBuffer result = </span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
StringBuffer();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
result.append(</span><span style="color: #2a00ff;">"toggleButton1 :
"</span><span style="color: black;">).append(</span><span style="color: #0000c0;">toggleButton1</span><span style="color: black;">.getText());</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
result.append(</span><span style="color: #2a00ff;">"\ntoggleButton2 :
"</span><span style="color: black;">).append(</span><span style="color: #0000c0;">toggleButton2</span><span style="color: black;">.getText());</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;">
Toast.</span><span style="color: black;"><i>makeText</i></span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,
result.toString(),</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: black;"> Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> }</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> });</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
</span></span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">
}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"> </span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">}</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><br /></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Run the application</b></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKWM6h_jpbdu9XhGlYqHiDGnm7eVuEAiqvUsKbFALa2dGZrs8YrM1CGZ5D7xLXoRaL3aFABCaWRGrgvT9V8rUUKgSwpUcY4DoUIBiflYxpIFDJRVLKkD5-iy14WHanu8y0SUkzJlg7fO3p/s1600/toggel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKWM6h_jpbdu9XhGlYqHiDGnm7eVuEAiqvUsKbFALa2dGZrs8YrM1CGZ5D7xLXoRaL3aFABCaWRGrgvT9V8rUUKgSwpUcY4DoUIBiflYxpIFDJRVLKkD5-iy14WHanu8y0SUkzJlg7fO3p/s640/toggel.png" width="384" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h4 style="background-color: white; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: inherit; font-size: 24px;">Download Source Code </span><span style="font-weight: normal;"><span style="color: blue; font-family: Arial, Helvetica, sans-serif;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoRHNtaEphRTdvbzA/edit" target="_blank">ToggelButtonExample.zip</a><span id="goog_301542373"></span><span id="goog_301542374"></span><a href="http://www.blogger.com/"></a></span></span></h4>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com2tag:blogger.com,1999:blog-6815866712748042162.post-7554868869820402522013-05-30T05:20:00.000-07:002013-05-30T21:12:20.990-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Android Radio Buttons </b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">In Android, you can use “</span><a href="http://developer.android.com/reference/android/widget/RadioButton.html" style="font-family: Arial, Helvetica, sans-serif;"><span class="s1"><span style="color: blue;">android.widget.RadioButton</span></span></a><span style="font-family: Arial, Helvetica, sans-serif;">” class to render radio button, and those radio buttons are usually grouped by </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;"><a href="http://developer.android.com/reference/android/widget/RadioGroup.html"><span class="s1" style="color: blue;">android.widget.RadioGroup</span></a>.</span><span style="font-family: Arial, Helvetica, sans-serif;"> If </span><span class="s2" style="font-family: Arial, Helvetica, sans-serif;">RadioButtons</span><span style="font-family: Arial, Helvetica, sans-serif;"> are in group, when one </span><span class="s2" style="font-family: Arial, Helvetica, sans-serif;">RadioButton</span><span style="font-family: Arial, Helvetica, sans-serif;"> within a group is selected, all others are automatically deselected.</span><br />
<div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">if you think that the user needs to see all available options side-by-side. If it's not necessary to show all options side-by-side, use a <a href="http://developer.android.com/guide/topics/ui/controls/spinner.html"><span class="s1"><span style="color: blue;">spinner</span></span></a> instead.</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
</div>
<div class="p1">
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>RadioButton Click Events</b></span></div>
</div>
<div class="p1">
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">When the user selects one of the radio buttons, the corresponding <span class="s1">RadioButton</span> object receives an on-click event.</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">To define the click event handler for a button, add the <a href="http://developer.android.com/reference/android/R.attr.html#onClick"><span class="s1"><span style="color: blue;">android:onClick</span></span></a> attribute to the <span class="s2"><RadioButton></span>element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The <a href="http://developer.android.com/reference/android/app/Activity.html"><span class="s1" style="color: blue;">Activity</span></a> hosting the layout must then implement the corresponding method or you can also define click event individually for each radiobutton in activity class as radioButton.setOnClickListner().</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
<span style="background-color: white; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif;">In this tutorial, we show you how to use XML to create two radio buttons, and grouped in a radio group. When button is clicked, display which radio button is selected.</span></span></div>
<div class="p1">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px;"><br /></span></div>
<div class="p1">
<h3 style="text-align: left;">
<span style="background-color: white; color: #3c3c3c; line-height: 36px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">2. RadioButton</span></span></h3>
</div>
<div class="p1">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><i><span style="background: #ffffff;"><?</span></i></span><span style="color: #3f7f7f;"><i><span style="background: #ffffff;">xml</span></i></span><span style="color: teal;"><i><span style="background: #ffffff;">
</span></i></span><span style="color: #7f007f;"><i><span style="background: #ffffff;">version</span></i></span><span style="color: black;"><i><span style="background: #ffffff;">=</span></i></span><span style="color: #2a00ff;"><i><span style="background: #ffffff;">"1.0"</span></i></span><span style="color: teal;"><i><span style="background: #ffffff;">
</span></i></span><span style="color: #7f007f;"><i><span style="background: #ffffff;">encoding</span></i></span><span style="color: black;"><i><span style="background: #ffffff;">=</span></i></span><span style="color: #2a00ff;"><i><span style="background: #ffffff;">"utf-8"</span></i></span><span style="color: teal;"><i><span style="background: #ffffff;">?></span></i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">LinearLayout</span>
<span style="color: #7f007f;">xmlns:android</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:orientation</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"vertical"</i></span>
<span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">RadioGroup</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/radiobuttongrp"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span>
<span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">RadioButton</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/radio1"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:text</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@string/ronaldo"</i></span>
</span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:checked</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"true"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">RadioButton</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/radio2"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:text</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@string/messi"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">RadioGroup</span><span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnDisplay"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:text</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@string/btn_display"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"></</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">LinearLayout</span></span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, Helvetica, sans-serif; font-size: 24px; line-height: 36px;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, Helvetica, sans-serif; font-size: 24px; line-height: 36px;"><b>3. Code </b></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><i><b><span style="background-color: white;">package</span></b></i></span><span style="color: black;"><i><span style="background: #ffffff;">
com.learnsimply.radiobuttonexample;</span></i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.view.View;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.view.View.OnClickListener;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Button;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.RadioButton;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.RadioGroup;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Toast;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>private</b></span><span style="color: black;">
RadioGroup </span><span style="color: #0000c0;">radioGroup</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>private</b></span><span style="color: black;">
RadioButton </span><span style="color: #0000c0;">radioButton</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>private</b></span><span style="color: black;">
Button </span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> setContentView(R.layout.</span><span style="color: #0000c0;"><i>activity_main</i></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> initializeClickListner();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
initializeClickListner() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">radioGroup</span><span style="color: black;">
= (RadioGroup) findViewById(R.id.</span><span style="color: #0000c0;"><i>radiobuttongrp</i></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">
= (Button) findViewById(R.id.</span><span style="color: #0000c0;"><i>btnDisplay</i></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">.setOnClickListener(</span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
OnClickListener() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onClick(View v) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
get selected radio button from radioGroup</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>int</b></span><span style="color: black;">
selectedId = </span><span style="color: #0000c0;">radioGroup</span><span style="color: black;">.getCheckedRadioButtonId();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
find the </span><span style="color: #3f7f5f;"><u>radiobutton</u></span><span style="color: #3f7f5f;">
by returned id</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">radioButton</span><span style="color: black;">
= (RadioButton) findViewById(selectedId);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> Toast.</span><span style="color: black;"><i>makeText</i></span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #0000c0;">radioButton</span><span style="color: black;">.getText(),
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> });</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;">}</span></span><br />
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><br /></span></span>
<span style="background-color: white; color: #3c3c3c; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Run the application</b></span></span><br />
<span style="background-color: white; color: #3c3c3c; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span>
<span style="background-color: white; color: #3c3c3c; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif;">Result here is Ronaldo when you click on display button</span></span><br />
<span style="background-color: white; color: #3c3c3c; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcMLKF3Cd5xwXcTIgpu0spMcOthNfj3s4KVIGpD9nr07ckIWUnXCOBFLIzE0xzA6Angij6WOBC5TlPg-mLQF4Ogq25Y5GaoG_QzlDY7Z3HRkVDyppmfemcvSfbB7KH4RGvcmzz2C2ZTMXi/s1600/radio_button.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcMLKF3Cd5xwXcTIgpu0spMcOthNfj3s4KVIGpD9nr07ckIWUnXCOBFLIzE0xzA6Angij6WOBC5TlPg-mLQF4Ogq25Y5GaoG_QzlDY7Z3HRkVDyppmfemcvSfbB7KH4RGvcmzz2C2ZTMXi/s1600/radio_button.png" width="384" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h4 style="background-color: white; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px;">Download Source Code </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoSk5iTGZZalBlUkU/edit" target="_blank">RadionButtonExample</a></span></h4>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-76832664167348347462013-05-29T06:41:00.000-07:002013-05-30T21:20:50.537-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Android Checkbox Example</b></span><br />
<br /></div>
<div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<div class="p1">
In Android, you can use “<a href="http://developer.android.com/reference/android/widget/CheckBox.html"><span class="s1" style="color: blue;">android.widget.CheckBox</span></a>” class to render a checkbox.</div>
<div class="p1">
<br /></div>
<div class="p2">
Checkboxes allow the user to select one or more options from a set. Typically, you should present each checkbox option in a vertical list.</div>
<div class="p2">
<br /></div>
<div class="p2">
To create each checkbox option, create a <span class="s2">CheckBox</span> in your layout. Because a set of checkbox options allows the user to select multiple items, each checkbox is managed separately and you must register a click listener for each one.</div>
<div class="p3">
<br /></div>
<div class="p1">
In this tutorial, we show you how to create checkboxes in XML file, and demonstrates the use of listener to check the checkbox state – checked or unchecked.</div>
</div>
<h4 style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
2. CheckBox</span></h4>
<h4 style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<div style="color: #3c3c3c; margin-bottom: 0cm;">
<div align="LEFT" style="margin-bottom: 0cm;">
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><span style="background-position: initial initial; background-repeat: initial initial;"><</span></span><span style="color: #3f7f7f;"><span style="background-position: initial initial; background-repeat: initial initial;">LinearLayout</span></span><span style="color: #3c3c3c;"><span style="background-position: initial initial; background-repeat: initial initial;">
</span></span><span style="color: #7f007f;"><span style="background-position: initial initial; background-repeat: initial initial;">xmlns:android</span></span><span style="color: black;"><span style="background-position: initial initial; background-repeat: initial initial;">=</span></span><span style="color: #2a00ff;"><i><span style="background-position: initial initial; background-repeat: initial initial;">"http://schemas.android.com/apk/res/android"</span></i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">tools:context</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:orientation</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"vertical"</i></span>
<span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">CheckBox</span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/checkBox1"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Messi"</u></i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:onClick</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"onCheckboxClicked"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">CheckBox</span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/checkBox2"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Ronaldo"</u></i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:onClick</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"onCheckboxClicked"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="color: black;"> </span>
</div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnDisplay"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Display"</u></i></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:onClick</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"onDisplayClicked"</i></span>
<span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="color: black;"> </span>
</div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
</div>
<div align="LEFT" style="font-weight: normal; margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"></</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">LinearLayout</span></span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">></span></span></span></div>
<span style="background-color: transparent; font-weight: normal;"><br /></span>
<span style="background-color: transparent; font-family: Arial, Helvetica, sans-serif; font-size: large;">3. Code </span></div>
</div>
</div>
</h4>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Attach the onCheckBoxClick listner to both the checkboxs and when you click the checkbox it shows the checkbox text as an toast message.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: #f9f9f9; line-height: 19px;">Within the </span><code style="background-color: #f9f9f9; line-height: 14px;"><a href="http://developer.android.com/reference/android/app/Activity.html" style="text-decoration: none;"><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Activity</span></a></code><span style="background-color: #f9f9f9; line-height: 19px;"> that hosts this layout, the following method handles the click event for both checkboxes:</span></span><br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<ol style="background-color: white; line-height: 21px; margin: 0px 0px 12px 36px; padding: 0px;">
<li style="line-height: 1.5;"><span style="font-family: Arial, Helvetica, sans-serif;">If checkbox id : “<strong>checkBox1</strong>” is checked, display a floating box and display the checkbox state of first checkbox.</span></li>
<li style="line-height: 1.5;"><span style="font-family: Arial, Helvetica, sans-serif;">If button is is clicked, display a floating box and display the both checkbox states.</span></li>
</ol>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="line-height: 24px;"><br /></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>package</b></span><span style="color: black;">
com.learnsimply.checkbox;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.view.View;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Button;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.CheckBox;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Toast;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> CheckBox
</span><span style="color: #0000c0;">checkBox1</span><span style="color: black;">,
</span><span style="color: #0000c0;">checkBox2</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> Button
</span><span style="color: #0000c0;">btnDisplay</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>protected</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> setContentView(R.layout.</span><span style="color: #0000c0;">activity_main</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #0000c0;">checkBox1</span><span style="color: black;">
= (CheckBox) findViewById(R.id.</span><span style="color: #0000c0;">checkBox1</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #0000c0;">checkBox2</span><span style="color: black;">
= (CheckBox) findViewById(R.id.</span><span style="color: #0000c0;">checkBox2</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> </span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> </span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCheckboxClicked(View view) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Is the view now checked?</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>boolean</b></span><span style="color: black;">
checked = ((CheckBox) view).isChecked();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #3f7f5f;">// Check which </span><span style="color: #3f7f5f;"><u>checkbox</u></span><span style="color: #3f7f5f;">
was clicked</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>switch</b></span><span style="color: black;">(view.getId())
{</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>case</b></span><span style="color: black;">
R.id.</span><span style="color: #0000c0;">checkBox1</span><span style="color: black;">:</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
Toast.</span><span style="color: black;">makeText</span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"Messi
"</span><span style="color: black;">+String.</span><span style="color: black;">valueOf</span><span style="color: black;">(checked),</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
Toast.</span><span style="color: #0000c0;">LENGTH_SHORT</span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;">
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>break</b></span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>case</b></span><span style="color: black;">
R.id.</span><span style="color: #0000c0;">checkBox2</span><span style="color: black;">:</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
Toast.</span><span style="color: black;">makeText</span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"Ronaldo
"</span><span style="color: black;">+String.</span><span style="color: black;">valueOf</span><span style="color: black;">(checked),</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
Toast.</span><span style="color: #0000c0;">LENGTH_SHORT</span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>break</b></span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;">
}</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> </span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onDisplayClicked(View view) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> StringBuffer
result = </span><span style="color: #7f0055;"><b>new</b></span><span style="color: black;">
StringBuffer();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> result.append(</span><span style="color: #2a00ff;">"Messi
check : "</span><span style="color: black;">).append(</span><span style="color: #0000c0;">checkBox1</span><span style="color: black;">.isChecked());</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> result.append(</span><span style="color: #2a00ff;">"\nRonaldo
check : "</span><span style="color: black;">).append(</span><span style="color: #0000c0;">checkBox2</span><span style="color: black;">.isChecked());</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> </span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> </span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> Toast.</span><span style="color: black;">makeText</span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,
result.toString(),</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: inherit;"><span style="color: black;"> Toast.</span><span style="color: #0000c0;">LENGTH_LONG</span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: inherit;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace; font-size: 11pt;">}</span><br />
<b style="color: #3c3c3c; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b>
<b style="color: #3c3c3c; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">4. Run the application</span></b></div>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
</div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrEb8AUIQos_rrJUHCs8na4dx8UwQi_LaulQRyZ3uScQz9x-b_oL7FGfegosckXrgTPgzgBcRqHAARIuv73tl1971JSDvY7eTuo5feS__iVyqVc5QEsI2I-_0EOF5A_DBwwVFjEJa1t3kZ/s1600/BOTH_CHECKED.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrEb8AUIQos_rrJUHCs8na4dx8UwQi_LaulQRyZ3uScQz9x-b_oL7FGfegosckXrgTPgzgBcRqHAARIuv73tl1971JSDvY7eTuo5feS__iVyqVc5QEsI2I-_0EOF5A_DBwwVFjEJa1t3kZ/s1600/BOTH_CHECKED.png" width="384" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI_pQoVw7WLZFfxXSsG6tw91hVs0G-yfPB6WYu3v-QSWR589Dy06zPl82VmdES02FGpWoew4knpdjN9L6_q7_9aowQbK0G_BPVEwyGbdgJGMRlxAwz9ajQ05JTApwJUp5-CuBQqBOcMlb2/s1600/single_checked.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI_pQoVw7WLZFfxXSsG6tw91hVs0G-yfPB6WYu3v-QSWR589Dy06zPl82VmdES02FGpWoew4knpdjN9L6_q7_9aowQbK0G_BPVEwyGbdgJGMRlxAwz9ajQ05JTApwJUp5-CuBQqBOcMlb2/s1600/single_checked.png" width="384" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h4 style="color: #3c3c3c; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, sans-serif; font-size: large;">Download Source Code </span><span style="font-weight: normal;"><span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoT011UFlpd214TDQ/edit" target="_blank">checkboxExample.zip</a></span></span></h4>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com1tag:blogger.com,1999:blog-6815866712748042162.post-66361149861695403242013-05-28T05:58:00.003-07:002013-05-30T21:31:52.837-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
Android Password Field</span></h2>
</div>
<div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, sans-serif;">In Android, you can use “</span><a href="http://developer.android.com/reference/android/widget/EditText.html" style="font-family: Arial, sans-serif;" target="_blank"><span style="color: blue;">android.widget.EditText</span></a><span style="font-family: Arial, sans-serif;">“, with </span><code style="background-color: #f7f7f9; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(225, 225, 232); font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; padding: 4px;"><span style="font-family: Arial, Helvetica, sans-serif;">inputType="textPassword</span><span style="font-family: Arial, sans-serif;">"</span></code><span style="font-family: Arial, sans-serif;"> for password component.</span></div>
<div style="background-color: white; font-family: Arial, sans-serif; line-height: 21px; margin-bottom: 20px;">
In this tutorial, we show you how to use XML to create a password field. When you click on the button, the password value will be displayed as a message (toast message).</div>
<h4 style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
2. Password</span></h4>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, Helvetica, sans-serif;">Open<span style="color: #3c3c3c;"> “<strong>res/layout/activity_main.xml</strong>” </span>file, add a password component.</span></div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: transparent; color: teal;"><i><</i></span><span style="background-color: transparent; color: #3f7f7f;"><i>LinearLayout</i></span><span style="background-color: transparent; color: teal;"><i>
</i></span><span style="background-color: transparent; color: #7f007f;"><i>xmlns:android</i></span><span style="background-color: transparent; color: black;"><i>=</i></span><span style="background-color: transparent; color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">tools:context</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:orientation</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"vertical"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">TextView</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #2a00ff;">
</span><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Password"</u></i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:textAppearance</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"?android:attr/textAppearanceLarge"</i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">EditText</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/editPassword"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:inputType</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"textPassword"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">requestFocus</span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: teal;"></</span><span style="color: #3f7f7f;">EditText</span><span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"> </span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnDisplayPass"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Display
Password"</u></i></span> <span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><br /></span></span></div>
<h4 style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
3. Code</span></h4>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 21px;">Inside activity "onCreate"</span><span style="background-color: white; font-size: 14px; line-height: 21px;"> method, attach a click listener on button, to display the password value.</span></span></div>
<div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">package</span><span style="color: black;">
com.learnsimply.edittextpassword;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.view.Menu;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.view.View;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.view.View.OnClickListener;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.Button;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.EditText;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.Toast;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">class</span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;">extends</span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> EditText
</span><span style="color: #0000c0;">edPass</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">protected</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">super</span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> setContentView(R.layout.</span><span style="color: #0000c0;">activity_main</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;">
</span><span style="color: #0000c0;">edPass</span><span style="color: black;"> =
(EditText)findViewById(R.id.</span><span style="color: #0000c0;">editPassword</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> Button
btnDisplay = (Button)findViewById(R.id.</span><span style="color: #0000c0;">btnDisplayPass</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> btnDisplay.setOnClickListener(</span><span style="color: #7f0055;">new</span><span style="color: black;">
OnClickListener() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
onClick(View v) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
</span><span style="color: #7f9fbf;">TODO</span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> Toast.</span><span style="color: black;">makeText</span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;">this</span><span style="color: black;">,
</span><span style="color: #0000c0;">edPass</span><span style="color: black;">.getText().toString(),
Toast.</span><span style="color: #0000c0;">LENGTH_SHORT</span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> });</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">boolean</span><span style="color: black;">
onCreateOptionsMenu(Menu menu) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
Inflate the menu; this adds items to the action bar if it is present.</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> getMenuInflater().inflate(R.menu.</span><span style="color: #0000c0;">activity_main</span><span style="color: black;">,
menu);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">return</span><span style="color: black;">
</span><span style="color: #7f0055;">true</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;">}</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><br /></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><br /></span></span></div>
<h4 style="text-align: left;">
<span style="background-color: white; line-height: 21px;"><b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Run the application</span></b></span></h4>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLUWDRYBwhGismlKy-SNSSjR7mkoYN1h_5uiO-M3AVnHFROnPbYsmFtCFykaM8w0EZQXsg-2lSclrCuAZqKxO5iGG06hYyuGASlRedCcpjImI681IymBTSTDpAT3T94HBweNtwUHMQly0u/s1600/password.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLUWDRYBwhGismlKy-SNSSjR7mkoYN1h_5uiO-M3AVnHFROnPbYsmFtCFykaM8w0EZQXsg-2lSclrCuAZqKxO5iGG06hYyuGASlRedCcpjImI681IymBTSTDpAT3T94HBweNtwUHMQly0u/s400/password.png" width="240" /></a></div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
<div>
<br /></div>
<div>
<h4 style="background-color: white; color: #3c3c3c; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, sans-serif; font-size: large;">Download Source Code </span><span style="font-weight: normal;"><span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoQjJ5TnROQ1BwSlE/edit" target="_blank">Android Password Example.zip</a></span></span></h4>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-4193717105430305282013-05-28T05:26:00.000-07:002013-06-01T06:09:13.148-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Android EditText Example</span></h2>
<div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, Helvetica, sans-serif;">In Android, you can use “<a href="http://developer.android.com/reference/android/widget/EditText.html" target="_blank"><span style="color: blue;">EditText</span></a>” class to create an editable textbox to accept user input.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">A text field allows the user to type text into your app. It can be either single line or multi-line. Touching a text field places the cursor and automatically displays the keyboard. In addition to typing, text fields allow for a variety of other activities, such as text selection (cut, copy, paste) and data look-up via auto-completion.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">You can add a text field to you layout with the </span><a href="http://developer.android.com/reference/android/widget/EditText.html" style="font-family: Arial, Helvetica, sans-serif;"><span class="s1" style="color: blue;">EditText</span></a><span style="font-family: Arial, Helvetica, sans-serif;"> object. You should usually do so in your XML layout with a </span><span class="s2" style="font-family: Arial, Helvetica, sans-serif;"><EditText></span><span style="font-family: Arial, Helvetica, sans-serif;"> element.</span><br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p1">
</div>
<h4 style="text-align: left;">
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Specifying the Keyboard Type</span></b></h4>
<div>
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Text fields can have different input types, such as number, date, password, or email address. The type determines what kind of characters are allowed inside the field, and may prompt the virtual keyboard to optimize its layout for frequently used characters.</span></div>
<div class="p1">
</div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">You can specify the type of keyboard you want for your <a href="http://developer.android.com/reference/android/widget/EditText.html"><span class="s1" style="color: blue;">EditText</span></a> object with the <a href="http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType"><span class="s1" style="color: blue;">android:inputType</span></a> attribute. For example, if you want the user to input an email address, you should use the <span class="s2">textEmailAddress</span> input type:</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><span style="background-position: initial initial; background-repeat: initial initial;"><</span></span><span style="color: #3f7f7f;"><span style="background-position: initial initial; background-repeat: initial initial;">EditText</span></span><span style="color: teal;"><span style="background-position: initial initial; background-repeat: initial initial;"></span></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/edEmail"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;"><u>android:hint</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Email"</u></i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #7f007f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">android:inputType</span></span></span><span style="color: black;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">=</span></span></span><span style="color: #2a00ff;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><i>"textEmailAddress"</i></span></span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">/></span></span></span></div>
</div>
</div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, Helvetica, sans-serif;">This tutorial show you how to create a edittext in XML file, and we can display message typed in the </span><span style="font-family: Arial, Helvetica, sans-serif;">edittext on TextChangeListner of edittext</span><span style="font-family: Arial, Helvetica, sans-serif;">.</span></div>
<h4 style="background-color: white; color: #3c3c3c; line-height: 36px; margin: 50px 0px 4px; text-align: left; text-rendering: optimizelegibility;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1. EditText</span></h4>
<div style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px;">
Open “<strong>res/layout/activity_main.xml</strong>” file, add a “<strong>EditText</strong>” component.</div>
<div style="background-color: white; color: #3c3c3c; line-height: 21px; margin-bottom: 20px;">
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><span style="background-position: initial initial; background-repeat: initial initial;"><</span></span><span style="color: #3f7f7f;"><span style="background-position: initial initial; background-repeat: initial initial;">LinearLayout</span></span><span style="color: teal;"><span style="background-position: initial initial; background-repeat: initial initial;">
</span></span><span style="color: #7f007f;"><span style="background-position: initial initial; background-repeat: initial initial;">xmlns:android</span></span><span style="color: black;"><span style="background-position: initial initial; background-repeat: initial initial;">=</span></span><span style="color: #2a00ff;"><i><span style="background-position: initial initial; background-repeat: initial initial;">"http://schemas.android.com/apk/res/android"</span></i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">tools:context</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:orientation</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"vertical"</i></span>
<span style="color: teal;">></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"> </span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">EditText</span>
</span></span>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/edText"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:text</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>""</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: #2a00ff;">
</span><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: teal;">/></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"> </span>
</div>
<div class="p1">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"></</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">LinearLayout</span></span></span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">></span></span></span></div>
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, Helvetica, sans-serif; line-height: 36px;"><br /></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 36px;"><b>2. EditText Listener</b></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">Attach a TextChange listener inside your activity “</span><code style="background-color: #f7f7f9; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(225, 225, 232); color: #0f3b68; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; font-size: 12px; padding: 4px;">onCreate()</code><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">” method, to monitor following events .</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">we are showing a message on the screen whenever a text in edittext is changed.</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">package</span><span style="color: black;">
com.learnsimply.edittextsample;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.text.Editable;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.text.TextWatcher;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
</span><span style="color: black;"><u>android.view.Menu</u></span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.EditText;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.Toast;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">class</span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;">extends</span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">protected</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">super</span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> setContentView(R.layout.</span><span style="color: #0000c0;">activity_main</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> EditText
edText = (EditText)findViewById(R.id.</span><span style="color: #0000c0;">edtext</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> edText.addTextChangedListener(</span><span style="color: #7f0055;">new</span><span style="color: black;">
TextWatcher() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
onTextChanged(CharSequence s, </span><span style="color: #7f0055;">int</span><span style="color: black;">
start, </span><span style="color: #7f0055;">int</span><span style="color: black;">
before, </span><span style="color: #7f0055;">int</span><span style="color: black;">
count) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
</span><span style="color: #7f9fbf;">TODO</span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> Toast.</span><span style="color: black;">makeText</span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;">this</span><span style="color: black;">,
s, Toast.</span><span style="color: #0000c0;">LENGTH_SHORT</span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
beforeTextChanged(CharSequence s, </span><span style="color: #7f0055;">int</span><span style="color: black;">
start, </span><span style="color: #7f0055;">int</span><span style="color: black;">
count,</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">int</span><span style="color: black;">
after) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
</span><span style="color: #7f9fbf;">TODO</span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
afterTextChanged(Editable s) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
</span><span style="color: #7f9fbf;">TODO</span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> });</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;">}</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
</div>
<h4 style="text-align: left;">
<span style="background-color: white; line-height: 21px;"><b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Run the application</span></b></span></h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrwJpzJYu5LiPNrbWOChu-u5lJYfK_lVSrXLMdGfqfPOxCLHZemlbhxVOf2XnOcGBNd30VC_GNb0p4w2oc4Bt2SvIG1gZfbG1CAt7ZdCTr8F3654ImJ8qE_fgWOzxXXB7x6lFaHr7tphiW/s1600/Edittext.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrwJpzJYu5LiPNrbWOChu-u5lJYfK_lVSrXLMdGfqfPOxCLHZemlbhxVOf2XnOcGBNd30VC_GNb0p4w2oc4Bt2SvIG1gZfbG1CAt7ZdCTr8F3654ImJ8qE_fgWOzxXXB7x6lFaHr7tphiW/s400/Edittext.png" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<h4 style="background-color: white; color: #3c3c3c; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, sans-serif; font-size: large;">Download Source Code </span><span style="font-weight: normal;"><span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZodFNCd1JPc3lvejg/edit" target="_blank">Edittextexample.zip</a><span id="goog_171765767"></span><span id="goog_171765768"></span><a href="http://www.blogger.com/"></a></span></span></h4>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-74631327526875974412013-05-24T03:48:00.000-07:002013-05-30T21:30:26.605-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Android Button Example</span></h2>
<div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<span style="font-family: Arial, Helvetica, sans-serif;">In Android, just use “<a href="http://developer.android.com/reference/android/widget/Button.html" target="_blank"><span style="color: blue;">android.widget.Button</span></a>” class to display a normal button.</span><br />
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">A button consists of text or an icon (or both text and an icon) that communicates what action occurs when the user touches it.</span></div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="p3">
<span style="font-family: Arial, Helvetica, sans-serif;">Depending on whether you want a button with text, an icon, or both, you can create the button in your layout in three ways:</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div class="p4">
<span style="font-family: Arial, Helvetica, sans-serif;"><span class="s1"><br />
</span>1.With text, using the <span class="s2"><span style="color: blue;">Button</span></span> class:</span></div>
</div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px;">
<div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="font-family: Monaco, monospace;"><span style="color: teal;"><</span><span style="color: #3f7f7f;"><span style="background-position: initial initial; background-repeat: initial initial;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"@string/button_text"</u></i></span></span></div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;">/></span></span></div>
<span style="background-color: #f9f9f9; line-height: 19px;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">2.With an icon, using the <span class="s1"><span style="color: blue;">ImageButton</span></span> class:</span></div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;">
</span><span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><Image</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnDisplay"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:</span><span style="color: #2a00ff;"><i>src="@drawable/button_icon"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">/></span></span></span></div>
<span style="background-color: #f9f9f9; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px;"><br /></span>
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><span class="s1">3.</span>With text and an icon, using the <span class="s2"><span style="color: blue;">Button</span></span> class with the <a href="http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableLeft"><span class="s3" style="color: blue;">android:drawableLeft</span></a> attribute:</span></div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><</span></span></span><span style="color: #3f7f7f;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:text</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@string/button_text"</i></span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;"><span style="color: #7f007f;">android:drawableLeft</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@drawable/button_icon"</i></span></span></span></div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: teal;"><span style="font-family: Monaco, monospace;"><span style="font-size: 11pt;">/></span></span></span></div>
<span style="background-color: #f9f9f9; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">In this tutorial, we show you how to display a normal button, add a click listener, when user click on the button, show the toast message.</span></div>
<div>
<span style="color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 36px;"><b>1. Add Button</b></span></div>
<div style="font-size: 14px;">
<br /></div>
<div style="font-family: Arial, sans-serif; font-size: 14px; margin-bottom: 20px;">
Open “<strong>res/layout/main.xml</strong>” file, add a button.</div>
<div style="font-size: 14px; margin-bottom: 20px;">
<div style="font-family: Arial, sans-serif;">
<em>File : res/layout/main.xml</em></div>
<div style="font-family: Arial, sans-serif;">
<br /></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">RelativeLayout</span>
<span style="color: #7f007f;">xmlns:android</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">tools:context</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="font-size: 11pt;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:id</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"@+id/btnHello"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:layout_width</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:layout_height</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:layout_centerHorizontal</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"true"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;">android:layout_centerVertical</span><span style="color: black;">=</span><span style="color: #2a00ff;"><i>"true"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f007f;"><u>android:text</u></span><span style="color: black;"><u>=</u></span><span style="color: #2a00ff;"><i><u>"Hello"</u></i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div style="margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><span style="font-size: 11pt;"></</span></span><span style="color: #3f7f7f;"><span style="font-size: 11pt;">RelativeLayout</span></span><span style="color: teal;"><span style="font-size: 11pt;">></span></span></span></div>
</div>
<div style="margin-bottom: 20px;">
<h4 style="line-height: 36px; margin: 50px 0px 4px; text-align: left; text-rendering: optimizelegibility;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">2. Code</span></h4>
<div>
<br />
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">package</span><span style="color: black;">
com.learnsimply.buttonclick;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.view.Menu;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.view.View;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.view.View.OnClickListener;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.Button;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">import</span><span style="color: black;">
android.widget.Toast;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">class</span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;">extends</span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">protected</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">super</span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> setContentView(R.layout.</span><span style="color: #0000c0;">activity_main</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> Button
btnClick = (Button)findViewById(R.id.</span><span style="color: #0000c0;">btnHello</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> btnClick.setOnClickListener(</span><span style="color: #7f0055;">new</span><span style="color: black;">
OnClickListener() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">void</span><span style="color: black;">
onClick(View v) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
</span><span style="color: #7f9fbf;">TODO</span><span style="color: #3f7f5f;">
Auto-generated method stub</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> Toast.</span><span style="color: black;">makeText</span><span style="color: black;">(MainActivity.</span><span style="color: #7f0055;">this</span><span style="color: black;">,
</span><span style="color: #2a00ff;">"Hello is clicked"</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;">LENGTH_LONG</span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> });</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> </span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">public</span><span style="color: black;">
</span><span style="color: #7f0055;">boolean</span><span style="color: black;">
onCreateOptionsMenu(Menu menu) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #3f7f5f;">//
Inflate the menu; this adds items to the action bar if it is present.</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> getMenuInflater().inflate(R.menu.</span><span style="color: #0000c0;">activity_main</span><span style="color: black;">,
menu);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"><span style="color: black;"> </span><span style="color: #7f0055;">return</span><span style="color: black;">
</span><span style="color: #7f0055;">true</span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;"> }</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;">}</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXUKPFZIAe3Ju8cN0lFmDPn13tyvc3RB1sJvu4IS-awPC3K3bRvwtft1zhDS8VRlkk8T2t0KMzrr-p1xcrPUqEt5Veig7TtAnFa2G9mv49UKh2JtLxjpdqqyjLTnn4VovCaefXeflb14HK/s1600/hello.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXUKPFZIAe3Ju8cN0lFmDPn13tyvc3RB1sJvu4IS-awPC3K3bRvwtft1zhDS8VRlkk8T2t0KMzrr-p1xcrPUqEt5Veig7TtAnFa2G9mv49UKh2JtLxjpdqqyjLTnn4VovCaefXeflb14HK/s400/hello.png" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h4 style="color: #3c3c3c; line-height: 36px; margin: 50px 0px 4px; text-rendering: optimizelegibility;">
<span style="font-family: Arial, sans-serif; font-size: large;">Download Source Code </span><span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoNTFZWTBjdmotdms/edit" target="_blank">Android button example.zip</a></span></h4>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large; font-weight: normal;"><br /></span></div>
</div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-87807527112963755632013-05-05T21:16:00.001-07:002013-05-30T21:21:40.011-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: x-large;"><b><span style="font-family: Arial, Helvetica, sans-serif;">Android Wrap_content And Match_parent</span></b></span><br />
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; color: #3c3c3c; line-height: 21px; text-align: -webkit-auto;">In Android, while designing layout you always put either "<span style="color: blue;">wrap_content</span>" or "<span style="color: blue;">match_parent</span>" </span><span style="background-color: white; color: #3c3c3c; line-height: 21px; text-align: -webkit-auto;">on component’s attribute on "<span style="color: blue;">layout_width</span>" and "<span style="color: blue;">layout_height</span>", </span><span style="background-color: white; color: #3c3c3c; line-height: 21px; text-align: -webkit-auto;"> </span><span style="background-color: white; color: #3c3c3c; line-height: 21px; text-align: -webkit-auto;">did any one know what’s the different?</span></span><br />
<br />
<ol style="background-color: white; color: #3c3c3c; line-height: 21px; margin: 0px 0px 12px 36px; padding: 0px; text-align: -webkit-auto;">
<li style="line-height: 1.5;"><span style="font-family: Arial, Helvetica, sans-serif;"><strong>wrap_content</strong> – The component just want to display big enough to enclose its content only.</span></li>
<li style="line-height: 1.5;"><span style="font-family: Arial, Helvetica, sans-serif;"><strong>fill_parent</strong> – The component want to display as big as its parent, and fill in the remaining spaces. (renamed match_parent in API Level 8)</span></li>
</ol>
<h3 style="text-align: left;">
<span style="background-color: white; color: #3c3c3c; font-size: 24px; line-height: 36px; text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;">1. wrap_content</span></span></h3>
<div>
<div style="background-color: white; line-height: 21px; margin-bottom: 20px; text-align: -webkit-auto;">
<span style="color: #3c3c3c; font-family: Arial, Helvetica, sans-serif;">A button component, set "</span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">wrap_content</span><span style="color: #3c3c3c; font-family: Arial, Helvetica, sans-serif;">"</span><span style="color: #3c3c3c; font-family: Arial, Helvetica, sans-serif;"> on both width and height attribute. It tell Android to display the button big enough to enclose it’s content “</span><em style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Button Hello World</span></em><span style="color: #3c3c3c; font-family: Arial, Helvetica, sans-serif;">” only.</span></div>
<div style="margin-bottom: 20px; text-align: -webkit-auto;">
<span style="color: #3c3c3c; font-family: Arial, Helvetica, sans-serif;"><span style="line-height: 21px;"></span></span></div>
<div style="margin-bottom: 20px; text-align: justify;">
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><i><</i></span><span style="color: #3f7f7f;"><i>LinearLayout</i></span><span style="color: teal;"><i>
</i></span><span style="color: #7f007f;"><i>xmlns:android</i></span><span style="color: #3c3c3c;"><i>=</i></span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #3c3c3c;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"fill_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:text</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"@string/hello_world"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">tools:context</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></div>
<br />
<div style="margin-bottom: 20px; text-align: justify;">
<span style="background-color: white; color: #6fa8dc; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSGRqr12PenCzibKwhRXYXfr1WRS3-wBf_gz3-Xou2tloXSWH4KgihdhvcXGqMGAl_OMFhPIiT3R1NEBG2ycD6VIqpRnVoF-h8e8SPu5JIQXjM7U9hO5QTDCLz__7bBCuXoN6H2IE_bHls/s1600/wrap.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSGRqr12PenCzibKwhRXYXfr1WRS3-wBf_gz3-Xou2tloXSWH4KgihdhvcXGqMGAl_OMFhPIiT3R1NEBG2ycD6VIqpRnVoF-h8e8SPu5JIQXjM7U9hO5QTDCLz__7bBCuXoN6H2IE_bHls/s400/wrap.png" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div style="background-color: white; margin-bottom: 20px; text-align: -webkit-auto;">
</div>
<h3 style="color: #3c3c3c; line-height: 21px; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">2. match_parent – width</span></h3>
<div style="font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px;">
<span style="color: #3c3c3c;">Change the "</span><span style="color: blue;">layout_width</span><span style="color: #3c3c3c;">" to "</span><span style="color: blue;">match_parent</span><span style="color: #3c3c3c;">", now, the button’s width will fill in the remaining spaces, just as big as it’s parent "</span><span style="color: blue;">Linearlayout</span><span style="color: #3c3c3c;">", but button’s height is still big enough to enclose it’s content only.</span></div>
<div style="margin-bottom: 20px;">
</div>
<div style="margin-bottom: 20px;">
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><</span><span style="color: #3f7f7f;">LinearLayout</span>
<span style="color: #7f007f;">xmlns:android</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #3c3c3c;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:text</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"@string/hello_world"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">tools:context</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></div>
</div>
<span style="font-size: x-large;"><b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ovjZEqYslFhFTs89y1BoDlWotoxoKzQC7HYa3Jqzdz0ESlsfwKTv_gvZoITXaVlQRZO2hx4Q8BU_ALdlBGgbclo2CoKsDYO2P4sIbOco7NMTOKb92v2C72qyf0jqrRkEZ7lU6dhINPt0/s1600/fill.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ovjZEqYslFhFTs89y1BoDlWotoxoKzQC7HYa3Jqzdz0ESlsfwKTv_gvZoITXaVlQRZO2hx4Q8BU_ALdlBGgbclo2CoKsDYO2P4sIbOco7NMTOKb92v2C72qyf0jqrRkEZ7lU6dhINPt0/s400/fill.png" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">3. match_parent – height</span></h3>
<div>
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;">Change the "<span style="color: blue;">layout_height</span>"</span><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;"> to "<span style="color: blue;">match_parent</span>"</span><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;">, now, the button’s height will fill in the remaining spaces, just as big as it’s parent "<span style="color: blue;">Linearlayout</span>"</span><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;">, but button’s width is still big enough to enclose it’s content only.</span></div>
<div>
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;"><br /></span></div>
<div style="text-align: left;">
<div style="text-align: left;">
<br />
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><i><</i></span><span style="color: #3f7f7f;"><i>LinearLayout</i></span><span style="color: teal;"><i>
</i></span><span style="color: #7f007f;"><i>xmlns:android</i></span><span style="color: #3c3c3c;"><i>=</i></span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #3c3c3c;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:text</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"@string/hello_world"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">tools:context</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></div>
</div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2TDsqwyQ_Bzx7mhzWZ1aVaEUN3K4P4rSBHJz11LpM0PVH0DJaqSlwvGoH5YF0m7kM-HL6d61_5klqkI66DGKBli8ykMQJOVR61Y8e7sU20e5hovb3pjFzUe1kVH2U1jfpyzjH7z0MKsp/s1600/fill_height.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2TDsqwyQ_Bzx7mhzWZ1aVaEUN3K4P4rSBHJz11LpM0PVH0DJaqSlwvGoH5YF0m7kM-HL6d61_5klqkI66DGKBli8ykMQJOVR61Y8e7sU20e5hovb3pjFzUe1kVH2U1jfpyzjH7z0MKsp/s400/fill_height.png" width="240" /></a></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><br /></span></span></div>
</div>
<div style="text-align: left;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;"><br /></span></div>
<div>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">4. match_parent – width, height</span></h3>
</div>
<div>
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;">Change the both "<span style="color: blue;">layout_width</span>" </span><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;">and "<span style="color: blue;">layout_height</span>"</span><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;"> to "<span style="color: blue;">match_parent</span>"</span><span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;">, the button will display as big as the whole device screen, it just fill in the entire screen space.</span></div>
<div>
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; text-align: -webkit-auto;"><br /></span></div>
<div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><i><</i></span><span style="color: #3f7f7f;"><i>LinearLayout</i></span><span style="color: teal;"><i>
</i></span><span style="color: #7f007f;"><i>xmlns:android</i></span><span style="color: #3c3c3c;"><i>=</i></span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #3c3c3c;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">Button</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:text</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"@string/hello_world"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">tools:context</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghRWXX74p-gccI266TS0ZmT35AXVX2oebXAWwq5KQcFmFRkKhqixc8q-PhYKxHHuK7JWq0IPseVrEBwH-Hq7MkwPMMEPSFAlG1DCX7FhXm-kba40SlMyHw4l6cTjCCZzsJI0Jw_dYyVDUx/s1600/both.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghRWXX74p-gccI266TS0ZmT35AXVX2oebXAWwq5KQcFmFRkKhqixc8q-PhYKxHHuK7JWq0IPseVrEBwH-Hq7MkwPMMEPSFAlG1DCX7FhXm-kba40SlMyHw4l6cTjCCZzsJI0Jw_dYyVDUx/s400/both.png" width="240" /></a></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><br /></span></span></div>
<div style="margin-bottom: 0cm;">
</div>
<h4 style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px; margin: 50px 0px 4px; text-align: -webkit-auto; text-rendering: optimizelegibility;">
References</h4>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html">Android documentation <span style="background-color: #f9f9f9; color: #333333; line-height: 32px; text-align: -webkit-auto;">ViewGroup.LayoutParams</span></a></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-27357402893079201882013-04-14T02:19:00.001-07:002013-05-30T21:21:53.026-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<b style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: x-large;">Android Life Cycle</span></b><br />
<br />
<br />
<div class="MsoNormal" style="background-color: white; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt; text-align: justify; vertical-align: baseline;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Android Activity Lifecycle Example Code Description</span></div>
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Here we will learn complete details about an Android Activity Lifecycle Example with details Code Description. Here we will learn details about all real time scenarios and different states of an Android Activity. Once you download the sample code example from here, then you can find line by line code description for an Android Activity. Anyway lets have a quick reminder on Android Activity Lifecycle. Below image will give us a overall idea about an Activity’s complete LifeCycle, then we will implement all details in our example.</span></div>
<div class="p2">
<br /></div>
<br />
<div class="p2">
<br /></div>
</div>
<div class="MsoNormal" style="background: white; line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify; vertical-align: baseline;">
<span style="color: #555555; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrZBo8DoqDJoP090EfiKpSwlIcnKekqtSvbX4ACy3gAQrTYbh3rjrfDSn3Mfs0MWmW2KuhcyFsgL-QT1P_LcmmpZspZetWJGiXGMBHe6py0q48ZUvFUJjoQOw44DilLSBHVkmBiMlAT8wK/s1600/Activity_life_cycle.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrZBo8DoqDJoP090EfiKpSwlIcnKekqtSvbX4ACy3gAQrTYbh3rjrfDSn3Mfs0MWmW2KuhcyFsgL-QT1P_LcmmpZspZetWJGiXGMBHe6py0q48ZUvFUJjoQOw44DilLSBHVkmBiMlAT8wK/s1600/Activity_life_cycle.jpg" width="472" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<h3 style="background-color: white; background-position: initial initial; background-repeat: initial initial; line-height: 15pt; margin: 0in 0in 12pt; text-align: justify; vertical-align: baseline;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Android Activity states</span></h3>
<div class="MsoNormal" style="text-align: justify;">
<span style="background: white; color: #555555; font-family: "Arial","sans-serif"; font-size: 10.0pt; line-height: 115%;"></span></div>
<h3 style="color: black; line-height: 15pt; margin-top: 0in; vertical-align: baseline;">
</h3>
<h3 style="background: white; line-height: 15.0pt; margin-top: 0in; vertical-align: baseline;">
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, sans-serif; padding: 0in;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">onCreate()</span></span><span style="font-family: Arial, sans-serif; font-size: 10pt;"><o:p></o:p></span></h3>
<div class="MsoNormal" style="text-align: justify;">
<span style="background: white; color: #555555; font-family: "Arial","sans-serif"; font-size: 10.0pt; line-height: 115%;"></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">onCreat Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one. </span><span style="font-family: Arial, Helvetica, sans-serif;">Always followed by </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">onStart()</span><span style="font-family: Arial, Helvetica, sans-serif;">.</span></div>
</div>
<div class="MsoNormal">
<h3 style="text-align: left;">
<span style="background-color: #fafafa; font-family: Arial, Helvetica, sans-serif; font-size: small; line-height: 115%;"><b><br /></b></span></h3>
<h3 style="text-align: left;">
<span style="background-color: #fafafa; font-family: Arial, Helvetica, sans-serif; font-size: small; line-height: 115%;"><b>onRestart()</b></span></h3>
</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">onRestart Called after your activity has been stopped, prior to it being started again. </span><span style="font-family: Arial, Helvetica, sans-serif;">Always followed by </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">onStart().</span></div>
</div>
<br />
<div class="MsoNormal">
</div>
<h3 style="background-color: white; line-height: 15pt; margin-top: 0in; text-align: justify; vertical-align: baseline;">
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, Helvetica, sans-serif; font-size: x-small; padding: 0in;">onStart()</span></h3>
<div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Called when the activity is becoming visible to the user.</span></div>
<div class="p2">
<span style="font-family: Arial, Helvetica, sans-serif;">Followed by onResume() if the activity comes to the foreground, or onStop()<span class="s1"> </span>if it becomes hidden.</span></div>
<br />
<div class="p3">
<br /></div>
</div>
</div>
<div>
<h3 style="background-color: white; color: black; font-family: 'Times New Roman'; line-height: 15pt; margin-top: 0in; text-align: justify; vertical-align: baseline;">
</h3>
<h3 style="background-position: initial initial; background-repeat: initial initial; line-height: 15pt; margin-top: 0in; vertical-align: baseline;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: small;">onResume()</span><span style="font-size: x-small;"><o:p></o:p></span></span></h3>
<div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it. </span><span style="font-family: Arial, Helvetica, sans-serif;">Always followed by </span><span class="s1" style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">onPause()</span>.</span></div>
</div>
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, sans-serif; font-size: 10pt; padding: 0in;"><span style="border: 1pt none windowtext; color: #555555; font-family: Arial, sans-serif; font-size: 10pt; padding: 0in;">
</span></span></div>
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, sans-serif; font-size: 10pt; padding: 0in;">
</span></div>
<br />
<div class="MsoNormal">
</div>
<h3 style="background-color: white; line-height: 15pt; margin-top: 0in; text-align: justify; vertical-align: baseline;">
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, Helvetica, sans-serif; font-size: x-small; padding: 0in;">onPause()</span></h3>
<div class="MsoNormal">
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">onPause Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc. Implementations of this method must be very quick because the next activity will not be resumed until this method returns.</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">Followed by either <span style="color: blue;"><span class="s1">onResume()</span> </span>if the activity returns back to the front, or <span class="s1"><span style="color: blue;">onStop()</span></span> if it becomes invisible to the user.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="background-color: #f7f7f7; background-position: initial initial; background-repeat: initial initial; line-height: 14.25pt; margin-bottom: 0.0001pt;">
</div>
<h3 style="background-color: white; line-height: 15pt; margin-top: 0in; text-align: justify; vertical-align: baseline;">
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, Helvetica, sans-serif; font-size: x-small; padding: 0in;">onStop()</span></h3>
<div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">onStop Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed.</span></div>
<br />
<div class="p3">
<span style="font-family: Arial, Helvetica, sans-serif;">Followed by either <span style="color: blue;"><span class="s1">onRestart()</span> </span>if this activity is coming back to interact with the user, or <span class="s1"><span style="color: blue;">onDestroy()</span></span> if this activity is going away</span></div>
</div>
<div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; line-height: 14.25pt; margin-bottom: 0.0001pt; text-align: justify;">
<br /></div>
<span style="border: 1pt none windowtext; color: #555555; font-family: Arial, sans-serif; font-size: 10pt; padding: 0in;">
</span></div>
<h3 style="text-align: left;">
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: small; line-height: 15pt;"><b>onDestroy()</b></span></h3>
<div>
<div class="MsoNormal">
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;"><span class="s1">The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called <a href="http://developer.android.com/reference/android/app/Activity.html#finish()"><span class="s2"><span style="color: blue;">finish()</span></span></a></span><span style="color: blue;"> </span>on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the <a href="http://developer.android.com/reference/android/app/Activity.html#isFinishing()"><span class="s3"><span style="color: blue;">isFinishing()</span></span></a><span class="s1"><span style="color: blue;"> </span>method.</span></span></div>
<span style="border: 1pt none windowtext; color: #555555; font-size: 10pt; padding: 0in;"><span style="font-family: Arial, Helvetica, sans-serif;"><span class="apple-converted-space"><span style="background-color: #f7f7f7; color: #222222; font-size: 10pt; line-height: 115%;"><br /></span></span></span></span></div>
<span style="border: 1pt none windowtext; color: #555555; font-size: 10pt; padding: 0in;">
</span></div>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">ActivityLifeCycle Example code :-</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: justify;">
</div>
<div class="separator" style="clear: both;">
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><i><b>package</b></i></span><span style="color: black;"><i>
com.learnsimply.activitylifecycle;</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.Toast;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
ActivityLifeCycle </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
setContentView(R.layout.<span style="color: #0000c0;"><i>main</i></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onCreate"</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onStart() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
<span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onStart();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onStart."</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onRestart() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
<span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onRestart();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onRestart."</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onResume() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
<span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onResume();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onResume."</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onPause() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
<span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onPause();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onPause."</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onStop() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
<span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onStop();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onStop."</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onDestroy() {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
<span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onStop();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
Toast.<span style="color: black;"><i>makeText</i></span><span style="color: black;">(</span><span style="color: #7f0055;"><b>this</b></span><span style="color: black;">,</span><span style="color: #2a00ff;">"onDestroy."</span><span style="color: black;">,
Toast.</span><span style="color: #0000c0;"><i>LENGTH_SHORT</i></span><span style="color: black;">).show();</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"> </span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">}</span></div>
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://docs.google.com/file/d/0B0PrpArwHdZoWmFvd3BqQlR1Q1U/edit" target="_blank">Download source code from this link</a></div>
<div class="MsoNormal" style="background: white; line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify; vertical-align: baseline;">
<div style="text-align: justify;">
<span style="color: #555555; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";"><br /></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-68652883849722872432013-04-13T23:43:00.000-07:002013-05-30T21:25:25.525-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><b>What is Android Activity ?</b></span><br />
<br />
<div>
<div style="margin-bottom: 0cm;">
<div class="MsoNormal" style="text-align: justify;">
<br />
<div class="p1">
<span style="font-family: Arial, Helvetica, sans-serif;">An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with <span style="color: blue;"><a href="http://developer.android.com/reference/android/app/Activity.html#setContentView(android.view.View)"><span class="s1">setContentView(View)</span></a>.</span> While activities are often presented to the user as full-screen windows</span></div>
</div>
</div>
<div style="margin-bottom: 0cm;">
</div>
<ul>
<li>The basis of android applications</li>
<li><span style="font-family: Arial, sans-serif;">A single Activity defines a single viewable </span>screen</li>
<li>Can have multiple per application</li>
<li>Each is a separate entity</li>
<li>They have a structured life cycle</li>
<li><span style="font-family: Arial, sans-serif;">Different events in their life happen either via the </span>user touching buttons or programmatically</li>
</ul>
<br />
<div style="margin-bottom: 0cm;">
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Arial, sans-serif;">The user
interface of an application is displayed on a device through an<span class="apple-converted-space"> </span></span><span style="font-family: "Arial","sans-serif";"><a href="http://developer.android.com/guide/topics/fundamentals/activities.html" target="_blank">Activity</a>, typically with
one Activity created for each unique screen. Internally there is a stack of
Activities, when moving from one screen to another, the next<span class="apple-converted-space"> </span><a href="http://developer.android.com/guide/topics/fundamentals/activities.html" target="_blank">Activity</a><span class="apple-converted-space"> to
be visible is pushed onto the top of the stack – put another way, the Activity
on the top of the stack is what is visible on the display.<span class="apple-converted-space"> </span></span><a href="http://developer.android.com/guide/topics/fundamentals/activities.html" target="_blank">Activities</a><span class="apple-converted-space"> are
popped from the stack by pressing the back button, which resumes the previous
Activity.</span><o:p></o:p></span></div>
</div>
</div>
<div>
<br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Android Activity</b></span></div>
<div>
<br /></div>
<div>
<div style="margin-bottom: 0cm;">
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Arial, sans-serif; font-size: 10pt;">When you
want to create a new Activity, you extend the Activity class. The code below
shows a simple starting point:</span><span style="font-family: "Arial","sans-serif"; font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><b>package</b></span>
<span style="color: #006699;">com.learnsimply.basicactivity</span><span style="color: #339933;">;</span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><b>import</b></span>
<span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><b>import</b></span>
<span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><b>public</b></span>
<span style="color: black;"><b>class</b></span> BasicActivity <span style="color: black;"><b>extends</b></span>
Activity
</div>
<div style="margin-bottom: 0cm;">
{</div>
<div style="margin-bottom: 0cm;">
<span style="color: green;"><span style="font-family: monospace;"><i><b>/**
Called when the activity is first created. */</b></i></span></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: monospace;">@Override</span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;">
</span><span style="color: #000066;"><span style="font-family: monospace;"><b>void</b></span></span><span style="font-family: monospace;">
onCreate</span><span style="color: #009900;"><span style="font-family: monospace;">(</span></span><span style="font-family: monospace;">Bundle
savedInstanceState</span><span style="color: #009900;"><span style="font-family: monospace;">)</span></span><span style="font-family: monospace;">
</span>
</div>
<div style="margin-bottom: 0cm;">
<span style="color: #009900;"><span style="font-family: monospace;">{</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: monospace;"><b>super</b></span></span><span style="font-family: monospace;">.</span><span style="color: #006633;"><span style="font-family: monospace;">onCreate</span></span><span style="color: #009900;"><span style="font-family: monospace;">(</span></span><span style="font-family: monospace;">savedInstanceState</span><span style="color: #009900;"><span style="font-family: monospace;">)</span></span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span></div>
<div style="margin-bottom: 0cm;">
<span style="color: #009900;"><span style="font-family: monospace;">}</span></span></div>
<div style="margin-bottom: 0cm;">
}</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Arial, sans-serif;">Once
created you’ll need to associate a layout of the UI for the Activity. The
recommended approach is to use an XML-based layout. For example, the layout
below shows how you might define a simple table.</span><span style="font-family: "Arial","sans-serif"; font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<pre class="western"><span style="color: #009900;"><span style="font-family: monospace;"><span style="color: black;"><b><?xml</b></span> <span style="color: #000066;">version</span>=<span style="color: red;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: red;">"utf-8"</span><span style="color: black;"><b>?></b></span></span></span>
<span style="color: #009900;"><span style="font-family: monospace;"><span style="color: black;"><b><TableLayout</b></span> <span style="color: #000066;">xmlns:android</span>=<span style="color: red;">"http://schemas.android.com/apk/res/android"</span></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:layout_width</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"fill_parent"</span></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:layout_height</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"fill_parent"</span></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:stretchColumns</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"1"</span></span><span style="color: black;"><span style="font-family: monospace;"><b>></b></span></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b><TableRow></b></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b><TextView</b></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:text</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"@string/row1a"</span></span><span style="color: black;"><span style="font-family: monospace;"><b>/></b></span></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b><TextView</b></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:text</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"@string/row1b"</span></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:gravity</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"right"</span></span><span style="color: black;"><span style="font-family: monospace;"><b>/></b></span></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b></TableRow></b></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b><TableRow></b></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b><TextView</b></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:text</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"@string/row2a"</span></span><span style="color: black;"><span style="font-family: monospace;"><b>/></b></span></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b><TextView</b></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:text</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"@string/row2b"</span></span></span>
<span style="color: #009900;"> <span style="color: #000066;"><span style="font-family: monospace;">android:gravity</span></span><span style="font-family: monospace;">=</span><span style="color: red;"><span style="font-family: monospace;">"right"</span></span><span style="color: black;"><span style="font-family: monospace;"><b>/></b></span></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b></TableRow></b></span></span>
<span style="color: black;"><span style="font-family: monospace;"><b></TableLayout></b></span></span></pre>
<div style="margin-bottom: 0cm;">
<br /></div>
<br />
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Arial, sans-serif;">Let’s
assume the layout about was created/saved in a file main.xml. Behind the
scenes, the Eclipse plugin will update the R.java file and make a reference to
the layout resources defined in main.xml. As an example:</span><span style="font-family: "Arial","sans-serif";"><o:p></o:p></span></div>
</div>
<br />
<br /></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<pre class="western"><span style="font-family: monospace;"><span style="color: black;"><b>package</b></span> </span><span style="color: #006699; font-family: 'Times New Roman'; white-space: normal;">com.learnsimply.basicactivity</span><span style="font-family: monospace;"><span style="color: #339933;">;</span></span>
<span style="font-family: monospace;"><span style="color: black;"><b>public</b></span> <span style="color: black;"><b>final</b></span> <span style="color: black;"><b>class</b></span> R <span style="color: #009900;">{</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>class</b></span></span><span style="font-family: monospace;"> attr </span><span style="color: #009900;"><span style="font-family: monospace;">{</span></span>
<span style="color: #009900;"><span style="font-family: monospace;">}</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>class</b></span></span><span style="font-family: monospace;"> drawable </span><span style="color: #009900;"><span style="font-family: monospace;">{</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> icon</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f020000</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: #009900;"><span style="font-family: monospace;">}</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>class</b></span></span><span style="font-family: monospace;"> layout </span><span style="color: #009900;"><span style="font-family: monospace;">{</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> main</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f030000</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: #009900;"><span style="font-family: monospace;">}</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>class</b></span></span><span style="font-family: monospace;"> string </span><span style="color: #009900;"><span style="font-family: monospace;">{</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> app_name</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f040004</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> row1a</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f040000</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> row1b</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f040001</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> row2a</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f040002</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: black;"><span style="font-family: monospace;"><b>public</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>static</b></span></span><span style="font-family: monospace;"> </span><span style="color: black;"><span style="font-family: monospace;"><b>final</b></span></span><span style="font-family: monospace;"> </span><span style="color: #000066;"><span style="font-family: monospace;"><b>int</b></span></span><span style="font-family: monospace;"> row2b</span><span style="color: #339933;"><span style="font-family: monospace;">=</span></span><span style="font-family: monospace;">0x7f040003</span><span style="color: #339933;"><span style="font-family: monospace;">;</span></span>
<span style="color: #009900;"><span style="font-family: monospace;">}</span></span>
<span style="color: #009900;"><span style="font-family: monospace;">}</span></span></pre>
<pre class="western"></pre>
<pre class="western"><div class="MsoNormal">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
</div>
<div class="MsoNormal" style="text-align: justify;">
<span style="background-color: #f9f9f9; background-position: initial initial; background-repeat: initial initial; font-family: "Arial","sans-serif"; line-height: 115%;">Notice the reference to main in the layout class. We can now update the BasicTable class defined above, which extended the Activity class, to tie the layout (table) to the Activity we defined, </span><br />
<span style="background-color: #f9f9f9; background-position: initial initial; background-repeat: initial initial; font-family: "Arial","sans-serif"; line-height: 115%;">we do this be calling the <b>setContentView()</b> method inside <b>onCreate()</b>:</span></div>
</pre>
<pre class="western"><pre class="java" style="-webkit-box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px !important; clear: none !important; color: #110000; line-height: 16px !important; overflow: visible !important; padding: 0px 4px !important; width: auto !important;"><span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">package</span> <span style="color: #006699; font-family: 'Times New Roman'; line-height: normal; white-space: normal;">com.learnsimply.basicactivity</span><span style="color: #339933; margin: 0px; padding: 0px;">;</span>
<span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">import</span> <span style="color: #006699; margin: 0px; padding: 0px;">android.app.Activity</span><span style="color: #339933; margin: 0px; padding: 0px;">;</span>
<span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">import</span> <span style="color: #006699; margin: 0px; padding: 0px;">android.os.Bundle</span><span style="color: #339933; margin: 0px; padding: 0px;">;</span>
<span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">public</span> <span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">class</span> BasicActivity <span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">extends</span> Activity
<span style="color: #009900; margin: 0px; padding: 0px;">{</span>
WebView webView<span style="color: #339933; margin: 0px; padding: 0px;">;</span>
<span style="color: green; font-style: italic; font-weight: bold; margin: 0px; padding: 0px;">/** Called when the activity is first created. */</span>
@Override
<span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">public</span> <span style="color: #000066; font-weight: bold; margin: 0px; padding: 0px;">void</span> onCreate<span style="color: #009900; margin: 0px; padding: 0px;">(</span>Bundle savedInstanceState<span style="color: #009900; margin: 0px; padding: 0px;">)</span>
<span style="color: #009900; margin: 0px; padding: 0px;">{</span>
<span style="color: black; font-weight: bold; margin: 0px; padding: 0px;">super</span>.<span style="color: #006633; margin: 0px; padding: 0px;">onCreate</span><span style="color: #009900; margin: 0px; padding: 0px;">(</span>savedInstanceState<span style="color: #009900; margin: 0px; padding: 0px;">)</span><span style="color: #339933; margin: 0px; padding: 0px;">;</span>
<span style="color: #666666; font-style: italic; margin: 0px; padding: 0px;">// Associate table layout to this Activity</span>
setContentView<span style="color: #009900; margin: 0px; padding: 0px;">(</span>R.<span style="color: #006633; margin: 0px; padding: 0px;">layout</span>.<span style="color: #006633; margin: 0px; padding: 0px;">main</span><span style="color: #009900; margin: 0px; padding: 0px;">)</span><span style="color: #339933; margin: 0px; padding: 0px;">;</span>
<span style="color: #009900; margin: 0px; padding: 0px;">}</span>
<span style="color: #009900; margin: 0px; padding: 0px;">}</span></pre>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Android Manifest</b></span></pre>
For each Activity, there needs to be an entry in the AndroidManifest.xml file,where you can define a theme,label,permissions, etc. </div>
</div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Arial","sans-serif"; font-size: 10.0pt; line-height: 115%;">Here is a sample manifest with one Activity:<o:p></o:p></span><br />
<span style="font-family: "Arial","sans-serif"; font-size: 10.0pt; line-height: 115%;"><br /></span></div>
<div style="text-align: justify;">
</div>
<b><?xml</b><span style="color: #009900;"> </span><span style="color: #000066;">version</span><span style="color: #009900;">=</span><span style="color: red;">"1.0"</span><span style="color: #009900;"> </span><span style="color: #000066;">encoding</span><span style="color: #009900;">=</span><span style="color: red;">"utf-8"</span><b>?></b><o:p></o:p>
<br />
<div style="text-align: justify;">
</div>
<b><manifest</b><span style="color: #009900;"> </span><span style="color: #000066;">xmlns:android</span><span style="color: #009900;">=</span><span style="color: red;">"http://schemas.android.com/apk/res/android"</span><o:p></o:p>
<br />
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"><span style="color: #009900;"> </span><span style="color: #000066;">package</span><span style="color: #009900;">=</span><span style="color: red;">"com.tabletest.table"</span><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"><span style="color: #009900;"> </span><span style="color: #000066;">android:versionCode</span><span style="color: #009900;">=</span><span style="color: red;">"1"</span><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"><span style="color: #009900;"> </span><span style="color: #000066;">android:versionName</span><span style="color: #009900;">=</span><span style="color: red;">"1.0"</span><b>></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b><application</b><span style="color: #009900;"> </span><span style="color: #000066;">android:icon</span><span style="color: #009900;">=</span><span style="color: red;">"@drawable/icon"</span><span style="color: #009900;"> </span><span style="color: #000066;">android:label</span><span style="color: #009900;">=</span><span style="color: red;">"@string/app_name"</span><b>></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b><activity</b><span style="color: #009900;"> </span><span style="color: #000066;">android:name</span><span style="color: #009900;">=</span><span style="color: red;">".TableActivity"</span><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"><span style="color: #009900;"> </span><span style="color: #000066;">android:label</span><span style="color: #009900;">=</span><span style="color: red;">"@string/app_name"</span><b>></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b><intent-filter></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b><action</b><span style="color: #009900;"> </span><span style="color: #000066;">android:name</span><span style="color: #009900;">=</span><span style="color: red;">"android.intent.action.MAIN"</span><span style="color: #009900;"> </span><b>/></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b><category</b><span style="color: #009900;"> </span><span style="color: #000066;">android:name</span><span style="color: #009900;">=</span><span style="color: red;">"android.intent.category.LAUNCHER"</span><span style="color: #009900;"> </span><b>/></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b></intent-filter></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"> <b></activity></b><o:p></o:p>
</pre>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
</div>
<b> </application></b><o:p></o:p>
<br />
<div style="text-align: justify;">
</div>
<pre style="text-align: justify;"><b></manifest></b><o:p></o:p></pre>
<pre><b>
</b></pre>
<pre><div class="MsoNormal">
</div>
<div style="text-align: justify;">
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<div style="text-align: justify;">
</div>
</div>
</pre>
<pre class="western"><pre class="java" style="-webkit-box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px !important; clear: none !important; line-height: 16px !important; overflow: visible !important; padding: 0px 4px !important; width: auto !important;"><span style="margin: 0px; padding: 0px;"><pre class="xml" style="-webkit-box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px !important; background-color: transparent !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px !important; clear: none !important; line-height: 16px !important; overflow: visible !important; padding: 0px 4px !important; width: auto !important;"><div>
</div>
</pre>
</span></pre>
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-76240536192980975592013-03-31T06:41:00.002-07:002013-05-30T21:24:30.242-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
</h2>
<h2 class="title" style="background-color: white; color: #333333; font-family: Lato, arial, sans-serif; font-size: 30px; margin: 20px 0px 0px; padding: 0px 0px 10px; text-align: -webkit-auto;">
Project Components</h2>
<div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">src
– your source code</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">gen
– auto-generated code (usually just R.java)</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">libs - Included libraries</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Resources</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Drawables
(like .png images)</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Layouts</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Values
(like strings)</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Manifest
file</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>SRC(Contains Source Code)</b></span></span><br />
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-right: 0.26cm;">
<span style="color: #0e2233;"><span style="font-family: Courier 10 Pitch;"><span style="color: black;">In
Android Development the src folder is where all you put your main
Java code</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-right: 0.26cm;">
<span style="color: #0e2233;"><span style="font-family: Courier 10 Pitch;"><span style="color: black;">EX. MainActivity.Java</span></span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<br /></div>
<br />
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>XML</b></span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="line-height: 100%;"><br /></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="line-height: 100%;">Used
to define some of the resources</span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
</div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Layouts
(UI)</span></span></div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Strings</span></span></div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Manifest
file</span></span></div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Shouldn’t
usually have to edit it directly, Eclipse can do that for you</span></span></div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Preferred
way of creating UIs</span></span></div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Separates
the description of the layout from any actual code that controls it</span></span></div>
<div align="LEFT" style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Can
easily take a UI from one platform to another</span></span></div>
<br />
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<b style="font-size: x-large; line-height: 11px;"><br /></b></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<b style="font-size: x-large; line-height: 11px;"><br /></b></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<b style="line-height: 11px;"><span style="font-size: large;">R Class</span></b><br />
<b style="line-height: 11px;"><span style="font-size: large;"><br /></span></b></div>
</div>
<h4>
<div align="LEFT" style="font-weight: normal; line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Auto-generated:
you shouldn’t edit it</span></span></div>
<div align="LEFT" style="font-weight: normal; line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Contains
IDs of the project resources</span></span></div>
<div align="LEFT" style="font-weight: normal; line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Enforces
good software engineering</span></span></div>
<div align="LEFT" style="font-weight: normal; line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Use
findViewById and Resources object to get access to the resources</span></span></div>
<div align="LEFT" style="font-weight: normal; line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Ex.
Button b = (Button)findViewById(R.id.button1)</span></span></div>
<div align="LEFT" style="font-weight: normal; line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Ex.
getResources().getString(R.string.<i>hello</i>));</span></span></div>
</h4>
<div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<br /></div>
<h3 style="text-align: left;">
<span style="line-height: 11px;"><span style="font-size: large;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"> Layout</span></span></span></span></h3>
<div>
<span style="line-height: 11px;"><span style="font-size: large;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><br /></span></span></span></span></div>
<div>
<span style="line-height: 100%; text-align: justify;">Eclipse
has a great UI creator</span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Generates
the XML for you</span></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Composed
of <i>View</i> objects</span></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Can
be specified for portrait and landscape mode</span></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Use
same file name, so can make completely different UIs for the
orientations without modifying any code.</span></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span></div>
<h3 style="text-align: left;">
<span style="font-size: large; line-height: 16px;"><b>Strings</b></span></h3>
<div>
<span style="font-size: large; line-height: 16px;"><b><br /></b></span></div>
<div>
<span style="line-height: 100%;"> In
res/values</span></div>
<div>
<div style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.23cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">strings.xml</span></span></div>
<div style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Application
wide available strings</span></span></div>
<div style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Promotes
good software engineering</span></span></div>
<div style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">UI
components made in the UI editor should have text defined in
strings.xml</span></span></div>
<div style="line-height: 90%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Strings
are just one kind of ‘Value’ there are many others</span></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<br /></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Menifest File</b></span>
</div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
<span style="font-size: large;"><b><br /></b></span></div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
</div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Contains
characteristics about your application</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">When
have more than one Activity in app, NEED to specify it in manifest
file</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.19cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Go
to graphical view of the manifest file</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.19cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Add
an Activity in the bottom right</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.19cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Browse
for the name of the activity</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Need
to specify Services and other components too</span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">Also
important to define permissions and external libraries, like Google
Maps API</span></span></div>
</div>
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
</div>
<h2 class="title" style="background-color: white; color: #333333; font-family: Lato, arial, sans-serif; margin: 20px 0px 0px; padding: 0px 0px 10px; text-align: -webkit-auto;">
<span style="font-size: large;">Drawables</span></h2>
<div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm;">
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm; margin-right: 0.26cm; margin-top: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">A
<em><span style="font-style: normal;">Drawable </span></em>resource is
a general concept for a graphic which can be drawn. The simplest case
is a graphical file, which would be represented in Android via a
<code class="western"><span style="font-family: Courier 10 Pitch;">BitmapDrawable
</span></code>class. Bitmaps are typically stored in one of
the<code class="western"><span style="font-family: Courier 10 Pitch;"><i>res/drawable
</i></span></code>folders. The Android project creation wizard
creates several of these folders by default, you can provide
different sized files for different resolutions of Android devices.
If you only provide one file for all sizes the Android system will
scale the resource.</span></span></div>
<br />
<div style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.26cm; text-align: left;">
</div>
<div style="line-height: 0.64cm; margin-right: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">In
additional to graphical files, Android supports XML drawables and
9-patch graphics. XML drawables are used to describe shapes (color,
border, gradient), State and Transitions and more.</span></span></div>
<div style="line-height: 0.64cm; margin-right: 0.26cm; text-align: left;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;">9-patch
graphics are used to define which part of a graphic should be
stretched if the </span></span><code class="western"><span style="color: black;"><span style="font-family: Courier 10 Pitch;">View
</span></span></code><span style="color: black;"><span style="font-family: Courier 10 Pitch;">which
uses this graphic is larger than the graphic.</span></span><br />
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span>
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Libs</b></span></span><br />
<span style="color: black;"><span style="font-family: Courier 10 Pitch; font-size: xx-small;"><b><br /></b></span></span>
<span style="background-color: white; color: #3e3e3e; font-family: Verdana, Geneva, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;">The /lib folder is used to import library files in project that executables make use of and also you can import third party library files .</span></div>
</div>
<br />
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="line-height: 11px;"><span style="font-size: large;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span></span></span></div>
<div align="LEFT" style="line-height: 100%; margin-bottom: 0cm; margin-top: 0.23cm;">
<span style="line-height: 11px;"><span style="font-size: large;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span></span></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0tag:blogger.com,1999:blog-6815866712748042162.post-52450661451718392302013-03-30T23:02:00.001-07:002013-05-30T21:28:29.132-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2 style="border: 0px; color: #333333; font-family: 'Skolar Bold', 'Times New Roman', serif; font-size: 2em; line-height: 1.1em; margin: 0px; outline: 0px; padding: 0.5em 0px 0px; vertical-align: baseline;">
Get Started Developing for Android with Eclipse</h2>
<div>
<br /></div>
<h4>
<span style="color: #333333; font-family: 'Skolar Bold', 'Times New Roman', serif; font-size: 1.5em; line-height: 1.3em;">Installing Eclipse and the Android SDK</span></h4>
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;">The
recommended environment for </span></span></span><strong><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">developing
Android applications</span></span></strong><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;"> is
Eclipse with the Android Development Toolkit (ADT) plugin installed.
I’ll discuss the process here. If you need more detail, Google’s
own </span></span></span><a href="http://developer.android.com/sdk/"><span style="text-decoration: none;"><span style="color: blue; font-family: Courier 10 Pitch;">developer
pages</span></span></a><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;"> do
a good job of explaining the installation and configuration process.</span></span></span></span></div>
<ul>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Download
the </span></span><span style="font-family: Courier 10 Pitch;"><a href="http://developer.android.com/"><span style="color: blue;">Android
SDK</span></a> </span><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">for
your platform (Windows, Mac OS X, or Linux).</span></span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="color: #333333;"><span style="font-family: Arial, Helvetica, sans-serif;">Extract
the downloaded file to somewhere on your hard drive (on Linux, I use
/media/a).</span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;"><span style="color: #333333;">If
you don’t already have Eclipse installed, download and install the</span><span style="color: blue;">
</span></span><span style="font-family: Courier 10 Pitch;"><a href="http://eclipse.org/downloads/packages/eclipse-ide-java-developers/galileosr2"><span style="color: blue;">Eclipse
IDE for Java Developers</span></a> </span><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">package.
For programming, Google recommends using Eclipse 3.5 (Galileo).</span></span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Run
Eclipse and choose </span></span><em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Help->Install
New Software</span></span></em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">.</span></span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Click
</span></span><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Add
</span></span><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">in
the Available Software window.</span></span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span class="s1">Enter </span><span class="s2">Android Development Tools </span><span class="s1">in the <i>Name </i>field, and <a href="https://dl-ssl.google.com/android/eclipse/"><span class="s3" style="color: blue;">https://dl-ssl.google.com/android/eclipse/</span></a></span><span class="s2"> </span><span class="s1">in the <i>Location </i>field.</span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Click
</span></span><em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">OK
</span></span></em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">and
check </span></span><em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">Developer
Tools </span></span></em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;">in
the list of available software. This will install the Android
Development Tools and DDMS, Android’s debugging tool.</span></span></span></div>
</li>
</ul>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw2_JQf_ZZpanT2GWGqlHrnsmqUdK7sF_COZXTSaGatyBf1BXu6-ce9TwwCGYly106unXPJzUeeh9UGbFdBPRd_Otaz4jRuEPcOVyZztG55vM-hrzhVhOnI7I4TkwCWY3QX3TLh01_Y_wa/s1600/eclipse_install_adt.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw2_JQf_ZZpanT2GWGqlHrnsmqUdK7sF_COZXTSaGatyBf1BXu6-ce9TwwCGYly106unXPJzUeeh9UGbFdBPRd_Otaz4jRuEPcOVyZztG55vM-hrzhVhOnI7I4TkwCWY3QX3TLh01_Y_wa/s1600/eclipse_install_adt.jpg" width="385" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;">Click </span></span><span style="font-family: Courier 10 Pitch;">Next</span><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;"> and </span></span><span style="font-family: Courier 10 Pitch;">Finish</span><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;"> to
install the plugin. You’ll need to restart Eclipse once everything
is installed.</span></span></span></div>
<ul>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;">When
Eclipse restarts, choose </span><span style="font-family: Courier 10 Pitch;">Window<i>-></i>Preferences
</span><span style="font-family: Courier 10 Pitch;">and
you should see </span><span style="font-family: Courier 10 Pitch;">Android</span><span style="font-family: Courier 10 Pitch;">listed
in the categories.</span></span></div>
</li>
</ul>
<div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;">You
now need to tell Eclipse where you’ve installed the Android SDK.
Click </span><em><span style="font-family: Courier 10 Pitch;">Android</span></em><span style="font-family: Courier 10 Pitch;">and
then </span><em><span style="font-family: Courier 10 Pitch;">Browse
</span></em><span style="font-family: Courier 10 Pitch;">to
select the location where you extracted the SDK files. For example,</span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">/media/a/android-sdk-linux<span class="s1">.</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPjh0mCfkwNNxo02PAGiJAJD1BcnWzd6-acoOlZA1AYx9sldiY2kZHjPlI6frRENIFIBCTyx1OoapvWaxTvjVwSz04P0AxV4I7h4D9fHDjHB9dLaBsaG5pdfRQFTzyDv5r_Z851RmOtIHP/s1600/eclipse_android_preferences.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="372" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPjh0mCfkwNNxo02PAGiJAJD1BcnWzd6-acoOlZA1AYx9sldiY2kZHjPlI6frRENIFIBCTyx1OoapvWaxTvjVwSz04P0AxV4I7h4D9fHDjHB9dLaBsaG5pdfRQFTzyDv5r_Z851RmOtIHP/s1600/eclipse_android_preferences.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; padding: 0cm;">
<span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><br /></span></span></span>
<br />
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li><span style="color: #333333; font-family: Arial, Helvetica, sans-serif; line-height: 0.64cm;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;">Click </span></span></span><em style="font-family: Arial, Helvetica, sans-serif; line-height: 0.64cm;"><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><i><span style="background-position: initial initial; background-repeat: initial initial;">OK</span></i></span></span></em><span style="color: #333333; font-family: Arial, Helvetica, sans-serif; line-height: 0.64cm;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;"> to
have Eclipse save the location of your SDK.</span></span></span></li>
</ul>
</div>
<ul>
</ul>
</div>
<h4>
</h4>
<h4>
<span style="font-size: large;">Android virtual device - Emulator</span></h4>
<br />
<h3 class="title" style="background-color: white; margin: 0px; padding: 0px 0px 10px;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">What is the Android Emulator?</span></h3>
<div>
<div align="LEFT" style="margin-bottom: 0cm;">
<br />
<span style="font-family: Arial, Helvetica, sans-serif; line-height: 24.1875px;">The Android Development Tools (ADT) include an emulator to run an Android system. The emulator behaves like a real Android deviceIin most cases) and allows you to test your application without having a real device. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif; line-height: 24.1875px;">You can configure the version of the Android system you would like to run, the size of the SD card, the screen resolution and other relevant settings. You can define several of them with different configurations.These devices are called Android Virtual Device and you can start several in parallel.</span><br />
<span style="line-height: 24.1875px;"><br /></span></div>
<h4>
</h4>
<h4>
<span style="font-size: large;">Emulator Shortcuts</span></h4>
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">The
following shortcuts are useful for working with the emulator.</span></span></span></span></div>
<div style="line-height: 0.64cm; margin-left: 0.26cm; margin-right: 0.26cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Alt</span></span></span></strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">+</span></span></span><strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Enter
</span></span></span></strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Maximizes
the emulator. Nice for demos.</span></span></span></span></div>
<div style="line-height: 0.64cm; margin-left: 0.26cm; margin-right: 0.26cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Ctrl</span></span></span></strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">+</span></span></span><strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">F11
</span></span></span></strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">changes
the orientation of the emulator.</span></span></span></span></div>
<div style="line-height: 0.64cm; margin-left: 0.26cm; margin-right: 0.26cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">F8
</span></span></span></strong><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Turns
network on / off.</span></span></span></span></div>
<div style="line-height: 0.64cm; margin-left: 0.26cm; margin-right: 0.26cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="font-weight: normal;"><br /></span></span></span></span></div>
<h4>
</h4>
<h4>
<span style="font-size: large;">Emulator <span style="color: #333333; font-family: Lato, arial, sans-serif;">Parameter</span></span></h4>
</div>
</div>
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">There
are lots of parameters, we can set while creating android virtual
device(AVD). </span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">The
graphics of the emulator can use the native GPU of the computer. This
makes the rendering in the emulator very fast. To enable this, add
the </span></span></span><code class="western"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">GPU
Emulation </span></span></span></code><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">property
to the device configuration and set it to </span></span></span><code class="western"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">true</span></span></span></code><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">.</span></span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
</div>
<div align="LEFT" style="margin-bottom: 0cm;">
<div style="line-height: 0.64cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">You
can also set the </span></span></span><code class="western"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">Enabled</span></span></span></code><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;"> flag
for Snapshots. This will save the state of the emulator and will let
it start much faster. Unfortunately currently native GPU rendering
and Snapshots do not work together.</span></span></span></span></div>
<div style="line-height: 0.64cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="background: #ffffff;"><br /></span></span></span></span>
</div>
<div class="separator" style="clear: both; line-height: 0.64cm; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKRQrdplu3R2cWwd6P8hfYrO2HmXhQroMhN8CENFHNyFxPaLoUzPt1JSR7tbEPz6RXbCBaxoFvy7LrNJRJmvTVfKqdCMKsK-px-CXxSkjCrXeWc24ISnz0E6P2V-thQRk7U40fpEC9lGiQ/s1600/AVD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKRQrdplu3R2cWwd6P8hfYrO2HmXhQroMhN8CENFHNyFxPaLoUzPt1JSR7tbEPz6RXbCBaxoFvy7LrNJRJmvTVfKqdCMKsK-px-CXxSkjCrXeWc24ISnz0E6P2V-thQRk7U40fpEC9lGiQ/s1600/AVD.png" width="276" /></a></div>
<div style="line-height: 0.64cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="background: #ffffff;"><br /></span></span></span></span></div>
<h4 style="line-height: 0.64cm;">
<span style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; line-height: 21px; text-align: -webkit-auto;"><span style="font-size: large;">Get you start in Android programming</span></span></h4>
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;">In
this tutorial, we show you how to create a simple “hello
world” </span></span><strong><span style="font-family: Courier 10 Pitch;"><b><span style="background: #ffffff;">Android</span></b></span></strong><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;"> project
in </span></span><strong><span style="font-family: Courier 10 Pitch;"><b><span style="background: #ffffff;">Eclipse
IDE + ADT plugin</span></b></span></strong><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">,
and run it with </span></span><strong><span style="font-family: Courier 10 Pitch;"><b><span style="background: #ffffff;">Android
Virtual Device (AVD)</span></b></span></strong><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;">.
The Eclipse ADT plugin provided easy Android project creation and
management, components drag and drop, auto-complete and many useful
features to speed up your Android development cycles.</span></span></span></div>
<h4 style="line-height: 0.64cm;">
</h4>
<h4 style="background-color: white; color: #3c3c3c; font-family: Arial, sans-serif; font-size: 24px; line-height: 36px; margin: 50px 0px 4px; text-align: -webkit-auto; text-rendering: optimizelegibility;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
Create Android Project</span></h4>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">In
Eclipse, select “File -> New -> Project….”, “Android
Project”, and input your application detail. Eclipse will create
all the necessary Android project files and configuration.</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="font-weight: normal;"><span style="background: #ffffff;"><br /></span></span></span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="font-weight: normal;"><span style="background: #ffffff;"><br /></span></span></span></span></span></div>
<div class="separator" style="clear: both; line-height: 0.64cm; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTqtI-AeNUuBL2W4SLDLqmL_D4FyHdv6eDc94cE8cgw6buDZgd_bDqNp7yNUNAfk4cHhyHF693MkRDxztFJgza6_fY3Y7ypgTOIWk2iK4tBNkblUCdyIsKmPrCVmuZJP49rIZgUeGH4XL_/s1600/HelloWorld.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTqtI-AeNUuBL2W4SLDLqmL_D4FyHdv6eDc94cE8cgw6buDZgd_bDqNp7yNUNAfk4cHhyHF693MkRDxztFJgza6_fY3Y7ypgTOIWk2iK4tBNkblUCdyIsKmPrCVmuZJP49rIZgUeGH4XL_/s1600/HelloWorld.png" width="640" /></a></div>
<div class="separator" style="clear: both; line-height: 0.64cm; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; line-height: 0.64cm; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; line-height: 0.64cm; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOV19w64JIhRQi6uc76vWQeRoUYIVYoi0jrbF56ZqB_FX0Co0dRQ4OVlLk1wLPwOYDX19JxJsjVeMWnj0Gbnsx77o7X5YcsJGpxBrYxRLGgTTOrUoDPjwmg5AILayWDpKBiXPklp0uC-am/s1600/project_files.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOV19w64JIhRQi6uc76vWQeRoUYIVYoi0jrbF56ZqB_FX0Co0dRQ4OVlLk1wLPwOYDX19JxJsjVeMWnj0Gbnsx77o7X5YcsJGpxBrYxRLGgTTOrUoDPjwmg5AILayWDpKBiXPklp0uC-am/s1600/project_files.png" width="640" /></a></div>
<div class="separator" style="clear: both; line-height: 0.64cm; text-align: center;">
<br /></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
</div>
<h4 style="line-height: 0.64cm;">
<span style="font-family: Courier 10 Pitch;"><span style="font-size: large;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Hello
World</span></span></span></h4>
<div style="font-weight: normal; line-height: 0.56cm; margin-bottom: 0.53cm;">
<span style="font-family: Arial, Helvetica, sans-serif;">Locate
the generated activity file, and modify a bit to output a string
“Hello World”.</span></div>
<div style="line-height: 0.56cm; margin-bottom: 0.53cm;">
<em><span style="font-family: Courier 10 Pitch;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">File
: MainActivity.java</span></i></span></em></div>
<div style="margin-bottom: 0.53cm;">
<em><span style="color: #3c3c3c;"><i></i></span></em></div>
<div style="margin-bottom: 0.53cm;">
<br />
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><i><b>package</b></i></span><span style="color: black;"><i>
com.learnsimply.helloworld;</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.os.Bundle;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.app.Activity;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
</span><span style="color: black;"><u>android.view.Menu</u></span><span style="color: black;">;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>import</b></span><span style="color: black;">
android.widget.TextView;</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>class</b></span><span style="color: black;">
MainActivity </span><span style="color: #7f0055;"><b>extends</b></span><span style="color: black;">
Activity {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"> </span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #3f5fbf;">/**
Called when the activity is first created. */</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #646464;">@Override</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>public</b></span><span style="color: black;">
</span><span style="color: #7f0055;"><b>void</b></span><span style="color: black;">
onCreate(Bundle savedInstanceState) {</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span><span style="color: #7f0055;"><b>super</b></span><span style="color: black;">.onCreate(savedInstanceState);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
setContentView(R.layout.<span style="color: #0000c0;"><i>activity_main</i></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
TextView text =
(TextView)findViewById(R.id.<span style="color: #0000c0;"><i>txtView</i></span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">
text.setText(<span style="color: #2a00ff;">"Hello
World"</span><span style="color: black;">);</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;">
</span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> }</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"> </span>
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;">}</span></div>
</div>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="font-weight: normal; line-height: 0.56cm;">
<em><span style="color: #3c3c3c;"><span style="font-family: Arial, Helvetica, sans-serif;">File : activity_main.xml</span></span></em></div>
<div style="font-weight: normal; line-height: 0.56cm;">
<em><span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><br /></span></span></em></div>
<div>
<em><span style="color: #3c3c3c;"></span></em><br />
<div>
<br />
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"><i><</i></span><span style="color: #3f7f7f;"><i>LinearLayout</i></span><span style="color: teal;"><i>
</i></span><span style="color: #7f007f;"><i>xmlns:android</i></span><span style="color: #3c3c3c;"><i>=</i></span><span style="color: #2a00ff;"><i>"http://schemas.android.com/apk/res/android"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">xmlns:tools</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"http://schemas.android.com/tools"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"match_parent"</i></span>
<span style="color: teal;">></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #3c3c3c;">
</span><span style="color: teal;"><</span><span style="color: #3f7f7f;">TextView</span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:id</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"@+id/txtView"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_width</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">android:layout_height</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>"wrap_content"</i></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #7f007f;">tools:context</span><span style="color: #3c3c3c;">=</span><span style="color: #2a00ff;"><i>".MainActivity"</i></span>
<span style="color: teal;">/></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: teal;"></</span><span style="color: #3f7f7f;">LinearLayout</span><span style="color: teal;">></span></span></div>
</div>
<em><span style="color: #3c3c3c;">
</span></em>
<br />
<div style="font-weight: normal; line-height: 0.56cm;">
<em><span style="color: #3c3c3c;"><br /></span></em></div>
<em><span style="color: #3c3c3c;">
</span></em></div>
<br />
<div style="line-height: 0.56cm; margin-bottom: 0.53cm;">
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 1.3em; text-align: -webkit-auto;"><b>Running Your Application</b></span></div>
<h4>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<em><span style="font-family: Courier 10 Pitch;"><span style="font-style: normal;"><span style="font-weight: normal;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Now
let’s try running the application in Eclipse. As this is the first
run, Eclipse will ask what type of project you are working on:</span></span></span></span></em></div>
<ul>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Choose
</span></span><em><span style="font-family: Courier 10 Pitch;"><i><span style="font-weight: normal;">Run->Run
</span></i></span></em><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">or
press </span></span><em><span style="font-family: Courier 10 Pitch;"><i><span style="font-weight: normal;">Ctrl+F11</span></i></span></em><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">.</span></span></span></div>
</li>
<li><div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Choose
</span></span><em><span style="font-family: Courier 10 Pitch;"><i><span style="font-weight: normal;">Android
Application </span></i></span></em><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">and
click </span></span><em><span style="font-family: Courier 10 Pitch;"><i><span style="font-weight: normal;">OK</span></i></span></em><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">.</span></span></span></div>
</li>
</ul>
<div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">Eclipse
will now try to run the application on an Android device. At the
moment, though, you don’t have any Android devices running, so the
run will fail and you’ll be asked to create a new </span></span><em><span style="font-family: Courier 10 Pitch;"><i><span style="font-weight: normal;">Android
Virtual Device </span></i></span></em><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;">(AVD).</span></span></span></div>
<div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
<span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="font-weight: normal;"><br /></span></span></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsK1Srh24srX9LkS8cunGxPCFUzdyQMl6xwm03tKwYg02fvUxx5x84aSAZZEcD5maFkJFlWO1rebB5D1vZzM-R9y5io_w3hHEO_Qvj0vdad1dS4vUBOaFVk9MV04pzYDUBEZDKi-Yo1nph/s1600/avd_error.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="128" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsK1Srh24srX9LkS8cunGxPCFUzdyQMl6xwm03tKwYg02fvUxx5x84aSAZZEcD5maFkJFlWO1rebB5D1vZzM-R9y5io_w3hHEO_Qvj0vdad1dS4vUBOaFVk9MV04pzYDUBEZDKi-Yo1nph/s1600/avd_error.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="background-position: initial initial; background-repeat: initial initial; border: none; line-height: 0.58cm; margin-bottom: 0cm; padding: 0cm;">
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<em><span style="font-family: Courier 10 Pitch;"><span style="font-style: normal;"><span style="font-weight: normal;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Now
create fresh android virtual device and test your application output.
</span></span></span></span></em>
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<em><span style="color: #333333;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="font-style: normal;"><span style="font-weight: normal;"><span style="background: #ffffff;"><br /></span></span></span></span></span></span></em></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1VdDVTcxBKE2qLZCwm45r1pMI6xnV7ukwJxEbICpqXtzGc_FAnbXTa-gsMq1CL0apS9x67DqnDtqUT51EyEV88x53-pSbQM7r6kbleHXEq5_EO8Q62Q_uJNkxDPeA_mikabyZG1zimfaB/s1600/AVD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1VdDVTcxBKE2qLZCwm45r1pMI6xnV7ukwJxEbICpqXtzGc_FAnbXTa-gsMq1CL0apS9x67DqnDtqUT51EyEV88x53-pSbQM7r6kbleHXEq5_EO8Q62Q_uJNkxDPeA_mikabyZG1zimfaB/s1600/AVD.png" width="276" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="line-height: 0.58cm;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="line-height: 0.58cm;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</h4>
<div style="line-height: 0.64cm;">
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Courier 10 Pitch;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Now Run your application and see output</b></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="font-weight: normal;"><span style="background: #ffffff;"><br /></span></span></span></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIEGg7yYMNulhV73gHa8U1sS4Q3DXbnGbY1AsOkQWPi8dtfxipbLF6ztuBfnjJuXr5UVB1ghZfd4F-V1R8ralfmLCigd8BBHZKOfCE62mHQEKC2SYA294nikCnEgmh0Z51ZGoMVpRAb_KA/s1600/output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIEGg7yYMNulhV73gHa8U1sS4Q3DXbnGbY1AsOkQWPi8dtfxipbLF6ztuBfnjJuXr5UVB1ghZfd4F-V1R8ralfmLCigd8BBHZKOfCE62mHQEKC2SYA294nikCnEgmh0Z51ZGoMVpRAb_KA/s1600/output.png" width="640" /></a></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><span style="font-weight: normal;"><span style="background-color: white;"><a href="https://docs.google.com/file/d/0B0PrpArwHdZoaTFNUkZ2Xy1vSzQ/edit" target="_blank"><span id="goog_671812356"></span>Download source code from this link<span id="goog_671812357"></span></a></span></span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<br /></div>
</div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="background: #ffffff;"><br /></span></span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: #3c3c3c;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="background: #ffffff;"><br /></span></span></span></span></div>
</div>
</div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0Southern Asia22.59372606392931 80.859375-6.57818693607069 39.550781 51.765639063929314 122.167969tag:blogger.com,1999:blog-6815866712748042162.post-33946331023533420312013-03-30T06:29:00.000-07:002013-05-30T04:15:06.977-07:00What is Android?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2 class="title" style="background-color: white; color: #333333; font-family: Lato, arial, sans-serif; margin: 20px 0px 0px; padding: 0px 0px 10px;">
<span style="font-size: large;">
What is Android?</span></h2>
<div class="MsoNormal">
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="font-family: Courier 10 Pitch;"><span style="font-family: Arial, Helvetica, sans-serif;">Android is
a Linux-based operating system designed primarily
for touchscreen mobile devices such
as smartphones and tablet computers. Initially
developed by Android, Inc., which Google backed financially
and later bought in 2005.<br /><br />The Android Software Development Kit
(Android SDK) provides all necessary tools to develop Android
applications. This includes a compiler, debugger and a device
emulator, as well as its own virtual machine to run Android
programs.<br /><br />Android allows background processing, provides a
rich user interface library, supports 2-D and 3-D graphics using the
OpenGL libraries, access to the file system and provides an embedded
SQLite database.</span></span></div>
</div>
<br />
<h2 style="text-align: left;">
<span style="background-color: white; line-height: 24px;"><span style="font-family: Lato, arial, sans-serif; font-size: large;"><b>WHY ANDROID ?</b></span></span></h2>
<div>
<span style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px;">
<div class="p1">
Simple and Powerfull SDK</div>
<div class="p1">
No licensing,distribution,or development fees</div>
<div class="p1">
Development over many platform</div>
<div class="p1">
Linux,Mac OS,Windows</div>
<div class="p1">
Excellent documentation</div>
</span></div>
<div>
<span style="background-color: white; line-height: 24px;">
</span></div>
<div>
<span style="background-color: white; line-height: 24px;">
</span>
<br />
<h3 style="font-family: Lato, arial, sans-serif; font-weight: bold; text-align: left;">
<span style="background-color: white; line-height: 24px;">
For us</span></h3>
<div>
<div style="line-height: 18.0pt; margin-bottom: .0001pt; margin: 0in;">
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;"> Java-based,
easy to import 3 rd party Java library</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff; font-family: Arial, Helvetica, sans-serif;"> Job
opportunity</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<br /></div>
</div>
</div>
<span style="background-color: white; line-height: 24px;">
</span></div>
<div>
<span style="background-color: white; line-height: 24px;"><span style="font-family: Lato, arial, sans-serif; font-size: x-large;"><b><br /></b></span></span></div>
<div>
<span style="background-color: white; line-height: 24px;"><span style="font-family: Lato, arial, sans-serif; font-size: large;"><b>ANDROID SDK FEATURE</b></span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"><span style="background: #ffffff;"> </span><span style="font-family: Courier 10 Pitch;"><span style="background-color: white;">GSM,
EDGE, and 3G networks, WiFi , Bluetooth</span></span></span></div>
<div align="LEFT" style="margin-bottom: 0cm;">
<span style="color: black; font-family: Arial, Helvetica, sans-serif;"> <span style="font-family: Courier 10 Pitch;">API
Support for Bluetoothe , WiFi Ad hoc mode</span></span></div>
<br />
<span style="background-color: white; font-family: Lato, arial, sans-serif; line-height: 24px;"><b>Libraries</b></span><br />
<div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background-color: white; font-family: Arial, Helvetica, sans-serif;">Media,
SQLite , WebKit, SSL</span></span></span><br />
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-size: x-small;"><span style="background: #ffffff;"><br /></span></span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="background-color: white; font-family: Lato, arial, sans-serif;"><b>Hardware control:</b></span></div>
</div>
<div>
<div style="margin-bottom: .0001pt; margin: 0in;">
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="background: #ffffff; font-family: Arial, Helvetica, sans-serif;">
<span style="font-family: Courier 10 Pitch;">Accelerometer, compass,
microphone, camera, GPS</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="background: #ffffff;"><span style="font-family: Arial, Helvetica, sans-serif;">touch
screen, power Location-based service, map (Google API)</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<br /></div>
</div>
<span style="background-color: white; line-height: 24px;">
</span></div>
<span style="background-color: white; line-height: 24px;">
</span>
<br />
<div style="font-family: Lato, arial, sans-serif;">
<span style="background-color: white; font-size: large; line-height: 24px;"><b>Google Play (Android Market)</b></span></div>
<span style="background-color: white; line-height: 24px;">
</span>
<br />
<div>
<div style="margin-left: 10px; margin-right: 10px;">
<div style="font-size: 16px;">
<br /></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white;">Google
offers the </span><em><span style="font-style: normal;"><span style="background: #ffffff;">Google
Play</span></span></em><span style="background-color: white;"> service
in which programmers can offer their Android application to Android
users. Google phones include the </span><em><span style="font-style: normal;"><span style="background: #ffffff;">Google
Play</span></span></em><span style="background-color: white;"> application
which allows to install applications.</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff; font-family: Arial, Helvetica, sans-serif;">Google
Play also offers an update service, e.g. if a programmer uploads a
new version of his application to Google Play, this service will
notify existing users that an update is available and allow to
install it.</span></span></span></div>
<div align="LEFT" style="line-height: 0.64cm; margin-bottom: 0cm;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">Google
Play used to be called </span></span></span><em><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="font-style: normal;"><span style="background: #ffffff;">Android
Market</span></span></span></span></em><span style="color: black;"><span style="font-family: Courier 10 Pitch;"><span style="background: #ffffff;">.</span></span></span></span></div>
</div>
<div style="font-family: Lato, arial, sans-serif; margin-left: 10px; margin-right: 10px;">
<span style="background-color: white; line-height: 24px;"><br /></span></div>
<div style="font-family: Lato, arial, sans-serif; font-size: 16px; margin-left: 10px; margin-right: 10px;">
<span style="background-color: white; line-height: 24px;"><br /></span></div>
</div>
<span style="background-color: white; line-height: 24px;">
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/14574703997327222530noreply@blogger.com0