編輯:關於Android編程
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { WheelMain wheelMain; EditText txttime; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txttime = (EditText) findViewById(R.id.txttime); Calendar calendar = Calendar.getInstance(); txttime.setText(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH) + ""); Button btnselecttime = (Button) findViewById(R.id.button1); btnselecttime.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { LayoutInflater inflater = LayoutInflater .from(MainActivity.this); final View timepickerview = inflater.inflate( R.layout.timepicker, null); ScreenInfo screenInfo = new ScreenInfo(MainActivity.this); wheelMain = new WheelMain(timepickerview, true); wheelMain.screenheight = screenInfo.getHeight(); String time = txttime.getText().toString(); Calendar calendar = Calendar.getInstance(); if (JudgeDate.isDate(time, "yyyy-MM-dd")) { try { calendar.setTime(dateFormat.parse(time)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); int h = calendar.getTime().getHours(); int m = calendar.getTime().getMinutes(); wheelMain.initDateTimePicker(year, month, day, h, m); new AlertDialog.Builder(MainActivity.this) .setTitle("選擇時間") .setView(timepickerview) .setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { txttime.setText(wheelMain.getTime()); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); } }); } }
最近做的項目有個需求就是判斷一下還 剩多少字符可輸入,也就是對EditText 的文本變化做監聽 ,功能實現了,但是感覺使用組合方式,每次都要編寫,還不如寫
智能手機的迅速普及,大大的豐富了我們的娛樂生活。現在大家都喜歡晚上睡覺前玩會兒手機,但是應用的日間模式往往亮度太大,對眼睛有較為嚴重的傷害。因此,如今的應用往往開發了 日
遇到此問題,可以安裝應用寶、騰訊手機管家等手機管理軟件,應該可正常讓Android設備和XP系統正常通信。喜歡折騰的朋友可以看下面的實踐總結。USB連接方式:
1.3D畫廊的實現 我們知道android系統已經為我們提供好了一個展示圖片的“容器”——Gallery,但