Skip to main content

Android Datepicker Example

Android Datepicker Example

activity_main.xml

File: activity_main.xml
  1. <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:id="@+id/textView1"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_alignParentLeft="true"  
  12.         android:layout_alignParentTop="true"  
  13.         android:layout_marginLeft="50dp"  
  14.         android:layout_marginTop="36dp"  
  15.         android:text="Current Date:" />  
  16.   
  17.     <Button  
  18.         android:id="@+id/button1"  
  19.         android:layout_width="wrap_content"  
  20.         android:layout_height="wrap_content"  
  21.         android:layout_alignParentBottom="true"  
  22.         android:layout_centerHorizontal="true"  
  23.         android:layout_marginBottom="140dp"  
  24.         android:text="Change Date" />  
  25.   
  26.     <DatePicker  
  27.         android:id="@+id/datePicker1"  
  28.         android:layout_width="wrap_content"  
  29.         android:layout_height="wrap_content"  
  30.         android:layout_above="@+id/button1"  
  31.         android:layout_centerHorizontal="true"  
  32.         android:layout_marginBottom="30dp" />  
  33.   
  34. </RelativeLayout>  

Activity class

File: MainActivity.java
  1. package com.example.datepicker2;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.view.Menu;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.widget.Button;  
  9. import android.widget.DatePicker;  
  10. import android.widget.TextView;  
  11. import android.widget.Toast;  
  12.   
  13. public class MainActivity extends Activity {  
  14.     DatePicker picker;  
  15.     Button displayDate;  
  16.     TextView textview1;  
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.activity_main);  
  21.           
  22.         textview1=(TextView)findViewById(R.id.textView1);  
  23.         picker=(DatePicker)findViewById(R.id.datePicker1);  
  24.         displayDate=(Button)findViewById(R.id.button1);  
  25.           
  26.         textview1.setText(getCurrentDate());  
  27.           
  28.         displayDate.setOnClickListener(new OnClickListener(){  
  29.             @Override  
  30.             public void onClick(View view) {  
  31.                 textview1.setText(getCurrentDate());  
  32.             }  
  33.               
  34.         });  
  35.     }  
  36.     public String getCurrentDate(){  
  37.         StringBuilder builder=new StringBuilder();  
  38.         builder.append("Current Date: ");  
  39.         builder.append((picker.getMonth() + 1)+"/");//month is 0 based  
  40.         builder.append(picker.getDayOfMonth()+"/");  
  41.         builder.append(picker.getYear());  
  42.         return builder.toString();  
  43.     }  
  44.     @Override  
  45.     public boolean onCreateOptionsMenu(Menu menu) {  
  46.         // Inflate the menu; this adds items to the action bar if it is present.  
  47.         getMenuInflater().inflate(R.menu.activity_main, menu);  
  48.         return true;  
  49.     }  
  50.   
  51. }  

Comments

Popular posts from this blog

Inverted Linear Quadtree: Efficient Top K Spatial Keyword Search

Inverted Linear Quadtree: Efficient Top K Spatial Keyword Search ABSTRACT: In this paper, With advances in geo-positioning technologies and geo-location services, there are a rapidly growing amount of spatiotextual objects collected in many applications such as location based services and social networks, in which an object is described by its spatial location and a set of keywords (terms). Consequently, the study of spatial keyword search which explores both location and textual description of the objects has attracted great attention from the commercial organizations and research communities. In the paper, we study two fundamental problems in the spatial keyword queries: top k spatial keyword search (TOPK-SK), and batch top k spatial keyword search (BTOPK-SK). Given a set of spatio-textual objects, a query location and a set of query keywords, the TOPK-SK retrieves the closest k objects each of which contains all keywords in the query. BTOPK-SK is the batch processing of sets...

A simple and reliable touch sensitive security system CODING

#include <REGX51.H> #include "lcd.c" #define MAX_DELAY() delay(65000) sbit Vibra_Sense=P3^1; sbit Buz=P1^0; void intro() {  lcd_init();  lcd_str("Touch Sensitive ",0x80);  lcd_str("Security System ",0xc0);  MAX_DELAY();MAX_DELAY();  lcd_clr();  }  void main()  { unsigned int i = 0, j= 0; intro();    while(1)    { lcd_str("Security Syst On",0x80); lcd_str("No Vibra Detectd",0xc0); Buz = 1; if(Vibra_Sense == 1) { while(Vibra_Sense == 1) delay(1000); } else { while(Vibra_Sense == 0) delay(1000); } Buz = 0; lcd_str("Vibraton Detectd",0xc0);delay(65000); while(1);    }  }

A Time Efficient Approach for Detecting Errors in Big Sensor Data on Cloud

A Time Efficient Approach for Detecting Errors in Big Sensor Data on Cloud Abstract                                                                                                                                                      ...