Package Name : selva.timepicker
Project Name : TimePicker
Version : 1.5 ( Supports 1.5 and above versions)
main.xml
<?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="TimePicker" />
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
android:layout_width="121dp"
android:layout_height="wrap_content"
android:text=" get Time" />
</LinearLayout>
<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="TimePicker" />
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
android:layout_width="121dp"
android:layout_height="wrap_content"
android:text=" get Time" />
</LinearLayout>
TimePickerActivity.java
package selva.datepicker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
public class TimePickerActivity extends Activity
{
TimePicker timePicker;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(false);
//---Button view---
Button btnOpen = (Button) findViewById(R.id.button1);
btnOpen.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),"Time selected:"
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
public class TimePickerActivity extends Activity
{
TimePicker timePicker;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(false);
//---Button view---
Button btnOpen = (Button) findViewById(R.id.button1);
btnOpen.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),"Time selected:"
+timePicker.getCurrentHour()+":"
+ timePicker.getCurrentMinute(),Toast.LENGTH_SHORT).show();
}
});
}
}
+ timePicker.getCurrentMinute(),Toast.LENGTH_SHORT).show();
}
});
}
}
click get Time
Click Here to download source code
No comments:
Post a Comment