activity_main.xml
<relativelayout android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
android:paddingbottom=
"@dimen/activity_vertical_margin"
android:paddingleft=
"@dimen/activity_horizontal_margin"
android:paddingright=
"@dimen/activity_horizontal_margin"
android:paddingtop=
"@dimen/activity_vertical_margin"
tools:context=
"com.sunil.calenderexample.MainActivity"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
>
<calendarview android:id=
"@+id/calendarView_cl"
android:layout_alignparentleft=
"true"
android:layout_alignparenttop=
"true"
android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
>
</calendarview></relativelayout>
MainActivity.java
package com.dhaval.calenderexample;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CalendarView;
import android.widget.CalendarView.OnDateChangeListener;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnDateChangeListener {
private CalendarView calenderview=
null
;
@Override
protected void onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calenderview=(CalendarView)findViewById(R.id.calendarView_cl);
calenderview.setOnDateChangeListener(
this
);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return
true
;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if
(id == R.id.action_settings) {
return
true
;
}
return
super
.onOptionsItemSelected(item);
}
@Override
public void onSelectedDayChange(CalendarView arg0, int arg1, int arg2, int arg3) {
Toast.makeText(getBaseContext(), arg1+
"/"
+arg2+
"/"
+arg3, Toast.LENGTH_LONG).show();
}
}
No comments:
Post a Comment