This is my first android app: a simple timer.
Screenshots:
http://i47.tinypic.com/zj8chu.jpg
http://i47.tinypic.com/fthcli.jpg
At the moment, I'm working on these 2 problems.
First, there's a textview under the clock, but it is not displayed (XML problem?).
Second, the timer doesn't work. Let's say 3 seconds is chosen as interval, than a text is supposed to be shown under the clock for each 3 seconds. But it doesn't.
This is my code, so far.
Reminder.java
main.xml
Screenshots:
http://i47.tinypic.com/zj8chu.jpg
http://i47.tinypic.com/fthcli.jpg
At the moment, I'm working on these 2 problems.
First, there's a textview under the clock, but it is not displayed (XML problem?).
Second, the timer doesn't work. Let's say 3 seconds is chosen as interval, than a text is supposed to be shown under the clock for each 3 seconds. But it doesn't.
This is my code, so far.
Reminder.java
Code:
package com.anta40.reminder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.TabSpec;
public class Reminder extends Activity{
public final int TIMER_DELAY = 1000;
public final int TIMER_ONE_MINUTE = 60000;
public final int TIMER_ONE_SECOND = 1000;
Timer timer;
TimerTask task;
TextView tv;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
tv = (TextView) findViewById(R.id.textview1);
tv.setText("BOOM!!!!");
tv.setVisibility(TextView.VISIBLE);
try {
this.wait(TIMER_DELAY);
}
catch (InterruptedException e){
}
tv.setVisibility(TextView.INVISIBLE);
}
};
TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabSpec spec = tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("Clock");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Settings");
tabs.addTab(spec);
tabs.setCurrentTab(0);
RadioGroup rgroup = (RadioGroup) findViewById(R.id.rgroup);
rgroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.om){
timer.schedule(task, TIMER_DELAY, 3*TIMER_ONE_SECOND);
}
else if (checkedId == R.id.twm){
timer.schedule(task, TIMER_DELAY, 6*TIMER_ONE_SECOND);
}
else if (checkedId == R.id.thm){
timer.schedule(task, TIMER_DELAY, 9*TIMER_ONE_SECOND);
}
}
});
}
}
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="62px">
<LinearLayout android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true">
<AnalogClock android:id="@+id/clock"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
/>
<TextView android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lalalala....."
/>
</LinearLayout>
<LinearLayout android:id="@+id/tab2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true">
<TextView android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Interval: "/>
<RadioGroup android:id="@+id/rgroup"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5px">
<RadioButton
android:id="@+id/om"
android:text="3 seconds" />
<RadioButton
android:id="@+id/twm"
android:text="6 seconds" />
<RadioButton
android:id="@+id/thm"
android:text="9 seconds" />
</RadioGroup>
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>