This program is for android date picker.
Step 1) Here is the main java program of your project
package abc.mca;
import abc.mca.R.string;
import
android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.DatePicker;
import
android.widget.TextView;
public class MymcaActivity extends Activity {
Button
btn;
DatePicker
dp;
/**
Called when the activity is first created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dp=(DatePicker)findViewById(R.id.datePick);
btn=
(Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated
method stub
TextView t=(TextView)findViewById(R.id.txt);
t.setText(dp.getDayOfMonth() +"/"+ dp.getMonth()+1+ "/"+ dp.getYear());
}
});
}
}
Step 2) Here is the code of your main.xml file
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txt"
/>
<DatePicker
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/datePick"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="Select Date"
/>
</LinearLayout>
but y its showng 11 instead of feb
ReplyDelete