In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to achieve Android imitating iPhone date and time selector". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Take a look at the effect picture first.
How to use
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 ("Select time") .setView (timepickerview) .setPositiveButton ("OK", new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {txttime.setText (wheelMain.getTime () ) .setNegativeButton ("cancel", new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {}) .NegativeButton (). Show ();}});}} "how Android implements an iPhone-like date and time selector" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.