i am developing an android application in which a datepicker is there to select the date of birth ... I need to display this date in a text view and this date has to be added into a single digit... and display in a textview.. i did code where the date is displyed in a textview but i need to display the total sum of it..
for example if date of birth is 04 02 1984 then 0+4 0+2 1+9+8+4 so answer is 4, 2, 4 and this has to be displayed separate in a textview.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DatePicker date = (DatePicker) findViewById(R.id.datePicker1);
final TextView tvDate = (TextView) findViewById(R.id.textView2);
date.init(date.getYear(), date.getMonth(), date.getDayOfMonth(),new OnDateChangedListener()
{
@Override
public void onDateChanged(DatePicker arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
int sum = 0;
String date=Integer.toString(arg3);
String month=Integer.toString(arg2);
String year=Integer.toString(arg1);
tvDate.setText(month+date+year);
}
} );
}
}