XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DEMO" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:text="Demo Button" android:textSize="20dp"/>
</LinearLayout>
JAVA CODE:
package com.demo.ui;
import java.util.Calendar;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class DemoButtonActivity extends Activity {
private int hour, minute;
static final int ID_TIMEPICKER = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button imageButton = (Button)findViewById(R.id.button1);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
showDialog(ID_TIMEPICKER);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch(id){
case ID_TIMEPICKER:
return new TimePickerDialog(this, timeSetListener, hour, minute, false);
default:
return null;
}
}
private TimePickerDialog.OnTimeSetListener timeSetListener= new
TimePickerDialog.OnTimeSetListener(){
public void onTimeSet(android.widget.TimePicker arg0, int arg1, int arg2) {
Toast.makeText(getBaseContext(),
String.valueOf(arg1) + ":" + String.valueOf(arg2),
Toast.LENGTH_LONG).show();
}};
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DEMO" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:text="Demo Button" android:textSize="20dp"/>
</LinearLayout>
JAVA CODE:
package com.demo.ui;
import java.util.Calendar;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class DemoButtonActivity extends Activity {
private int hour, minute;
static final int ID_TIMEPICKER = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button imageButton = (Button)findViewById(R.id.button1);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
showDialog(ID_TIMEPICKER);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch(id){
case ID_TIMEPICKER:
return new TimePickerDialog(this, timeSetListener, hour, minute, false);
default:
return null;
}
}
private TimePickerDialog.OnTimeSetListener timeSetListener= new
TimePickerDialog.OnTimeSetListener(){
public void onTimeSet(android.widget.TimePicker arg0, int arg1, int arg2) {
Toast.makeText(getBaseContext(),
String.valueOf(arg1) + ":" + String.valueOf(arg2),
Toast.LENGTH_LONG).show();
}};
No comments:
Post a Comment