玩转FPGA山寨版

看了《玩转FPGA》,写的不错,写写山寨版和大家交流!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
package com.neddy;

import java.util.Calendar;

import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class HelloTimePicker extends Activity
{
private TextView mTimeDisplay;
private Button mPickTime;

private int mHour;
private int mMinute;
private OnTimeSetListener mTimeSetListener=
new OnTimeSetListener()
{
public void onTimeSet(TimePicker view ,int hourOfDay,int minute)
{
mHour
= hourOfDay;
mMinute
=minute;
updateDisplay();
}
};

static final int TIME_DIALOG_ID=0;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mTimeDisplay
=(TextView)findViewById(R.id.timeDisplay);
mPickTime
=(Button)findViewById(R.id.pickTime);

mPickTime.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View v)
{
showDialog(TIME_DIALOG_ID);
}
});

final Calendar c=Calendar.getInstance();
mHour
=c.get(Calendar.HOUR_OF_DAY);
mMinute
=c.get(Calendar.MINUTE);

updateDisplay();
}

private void updateDisplay()
{
mTimeDisplay.setText(
new StringBuilder()
.append(pad(mHour)).append(
":")
.append(pad(mMinute)));

}

private static String pad(int c)
{
if(c>=10) return String.valueOf(c);
else return "0" + String.valueOf(c);
}

protected Dialog onCreateDialog(int id)
{
switch(id)
{
case TIME_DIALOG_ID:
return new TimePickerDialog(this,mTimeSetListener, mHour, mMinute, false);
}
return null;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation
="vertical"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
>
<TextView
android:id="@+id/timeDisplay"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
=""
/>
<Button
android:id="@+id/pickTime"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="Change the time"
/>
</LinearLayout>

posted on 2011-09-16 20:44  Neddy11  阅读(1126)  评论(0编辑  收藏  举报