Google Android Tutorial
Demo 3 - Ticker
The third demo is a 'ticker' having a textbox for entering the ticker's text, a ticker(timer) , two labels(editview) one for status and the other for diplaying the sliding message.
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <EditText android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Ticker android:id="@+id/ticker1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dip" /> <TextView android:id="@+id/label1" android:layout_width="wrap_content" android:layout_height="fill_parent" /> </Ticker> <TextView android:id="@+id/label2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dip" /> </LinearLayout>
LinearLayout with vertical orientation is like FlowLayout but in a vertical direction.

package mypack.mydemos;
import android.app.Activity;
import android.os.Handler;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import java.util.Map;
public class demo extends Activity
implements Ticker.TickerListener {
Ticker ticker1;
TextView label1, label2;
EditText text1;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ticker1 = (Ticker) findViewById(R.id.ticker1);
label1 = (TextView) findViewById(R.id.label1);
label2 = (TextView) findViewById(R.id.label2);
text1 = (EditText) findViewById(R.id.text1);
ticker1.setTickerListener(this);
text1.setOnClickListener(new clicker());
}
class clicker implements EditText.OnClickListener {
public void onClick(View v) {
label1.setText(text1.getText());
ticker1.startTicker();
label2.setText("Ticking...");
}
}
public void onTickerFinished(Ticker view) {
label2.setText("Done!");
}
}
Demo 4 - Checkbox
Copy this to tools\demo\res\layout\
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/ apk/res/android"> <CheckBox android:id="@+id/check1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="java" android:layout_x="50px" android:layout_y="22px"> </CheckBox> <CheckBox android:id="@+id/check2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="C#" android:layout_x="50px" android:layout_y="72px"> </CheckBox> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Confirm" android:layout_x="60px" android:layout_y="122px"> </Button> <EditText android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="EditText" android:textSize="18sp" android:layout_x="60px" android:layout_y="202px"> </EditText> </AbsoluteLayout>
To be copied to tools\demo\mypack\mydemos
package mypack.mydemos;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class demo extends Activity
{
Button button1;
CheckBox check1, check2;
EditText text1;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
text1 = (EditText) this.findViewById(R.id.text1);
check1 = (CheckBox) findViewById(R.id.check1);
check2 = (CheckBox) findViewById(R.id.check2);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String r = "";
if (check1.isChecked())
{
r = r + "java" + "\n";
}
if (check2.isChecked())
{
r = r + "c#";
}
text1.setText(r);
}
}
}
This is just the usual Java code and needs very little explanation. The only difference is the way , the controls are defined ( through res\layout\xml file).
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Paul Bourdeaux replied on Thu, 2008/06/05 - 8:38am
Great article and tutorial. My company has been digging into Android lately, and you have a lot of helpful links and info for developers who are just starting with it. Thanks!
Musa Musa L replied on Mon, 2008/06/09 - 6:10am
Hello,
Great tutorial.. I am trying to run the example on openSuSE 10.3 with jdk6 update 6 and i keep on getting the following error message
Application error: mypack.mydemos
An error has occured in mypack.mydemos.
Unable to start activity ComponentInfo{mypack.mydemos/mypack.mydemos.demo}:java.lang.ClassCastException:Landroid/widget/TextView;.
What do you think is going on? I followed the steps exactly as you outlined..
I'd appreciate any help
Musa Musa L replied on Tue, 2008/06/10 - 2:15pm
in response to:
Musa Musa L
Kim Hoang replied on Mon, 2008/07/21 - 1:18pm
shanmugavel .s replied on Tue, 2008/09/09 - 12:51pm
william mensah replied on Thu, 2008/10/23 - 4:30pm
line 5: xmlns:android="http://schemas.android.com/ apk/res
the space between .com/ apk causes errors. Just thought I'd throw it out there. Got me puzzled for a while.
Good tutorial though! Very helpful. Need one on databases though; that would be nice :). keep up the good work.
william mensah replied on Thu, 2008/10/23 - 4:32pm
joby nk replied on Mon, 2008/12/29 - 7:02am
Hello,
great tutorial, iam trying to this code in Eclipd IDE , the first two demos working fine,but the Demo-3
throws an error "Ticker.TickerListener cannot be resolved to a type" when we implements the demo class by Ticker.TickerListener . why this error comes ,is there any other library need to link or anythng want to import.Hopfully expecting reply
Naina Kiran replied on Fri, 2009/01/16 - 3:41am
Hi Geetha,
This is Naina. I have recently started working on android. I have written 1 or 2 small applications. I went through the link, [url=http://geeth.ganesan.googlepages.com/android-tutorial]geeth.ganesan - ANDROID-TUTORIAL[/url]. I am trying to use the Spinner application written by you. I tried to run the same Spinner application on the android emulator using Eclipse IDE. But its not working. Iam getting the following exception error.
The application spin_and(process com.example.android.spin_and) has stopped unexpectedly. Please try again. Force Close.
I am not understanding where is the problem. I did not get any errors also. Please help me out.
Thanks,
Naina
Rakesh sharma replied on Tue, 2009/03/03 - 3:34pm
padma bhujangaiah replied on Wed, 2009/04/08 - 8:45am
in response to:
joby nk
padma bhujangaiah replied on Wed, 2009/04/08 - 8:49am
rajesh Vijayanadhan replied on Thu, 2009/07/02 - 6:23am
Hi,
I had creates a gallery with some images and its working fine for me.
Is there any way to put a seeker in the window for gallery.Is there any way to start a slide show(with gallery) when startActivity?
Please give me some suggestions...
Thanks And Regards,
Rajesh.V
Michael Maguire replied on Thu, 2010/05/13 - 5:14pm
The Spinner example has a space in the main.xml source:
which caused my version of the demo to crash each time it started up with LogCat error:
Binary XML file line #2: You must supply a layout_width attribute
Nagesh Golem replied on Fri, 2011/02/04 - 12:29am
Hello Experts,
I am new to android development, i am developing one application which needs to play an audio song to callee when call is lifted by callee, and automatically call has to be disconnected automatically when audio song playing completed . i tried to find in android API for any classes or methods to do this, but failed to find... please help me how to do this.. your answer could be helpful to me...please do reply Thank you in advance..
Amit Panchal replied on Fri, 2011/02/11 - 9:30am
Vinod Verma replied on Wed, 2011/03/23 - 1:10am
in response to:
Kim Hoang
Vinod Verma replied on Wed, 2011/03/23 - 1:16am
in response to:
shanmugavel .s
Pasta Kare replied on Mon, 2011/04/18 - 8:17pm
but this can add to the experience for me, maybe good to try.
Reza Gholami replied on Thu, 2011/08/18 - 11:57am
in response to:
Kim Hoang
Hi Kim,
I've seen your post about mobile app engineer for an Android project. I'm interested and have developed Java based apps in many frameworks such as SaaS and financial projects and recently Google Android apps on NetBeans
IDEs(6.8, 6.9,6.9.1, 7, and latest version7.0.1) and Eclipse tools and platforms. Furthermore, I'm skilled developper in Web EE and MVC architecture including JSP/Servlet and JSF and Struts frameworks.
I look forward to hearing from you.
Please email (rgholami@comcast.net) or call me (925) 381-8994.
Thank you, Reza Gholami