Reputation: 1854
I have three view items. 1. Button 2. CalendarView 3. TextView I am trying to display the selected date on TextView when i select the date AND click on the Button. Date should only appear in the TextView when the Button is clicked. Here is my code:
CalendarView cal = null;
TextView text = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cal = (CalendarView) findViewById(R.id.calendarView);
Button but = (Button) findViewById(R.id.button);
}
void Touchy(View view){
text = (TextView) findViewById(R.id.textView);
cal.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
text.setText("");
int d = dayOfMonth;
int m = month;
int y = year;
String c = d+"-"+m+"-"+y;
text.append(c);
}
});
}
XML
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/button"
android:layout_gravity="right|top"
android:onClick="Touchy"/>
However the app stops when i click on the button. What could possibly be wrong?
Upvotes: 2
Views: 2970
Reputation: 157437
the signature of the method you posted is wrong. It should be
public void Touchy(View view) {}
Upvotes: 1