Reputation: 1364
Hi I am developing an android app...in which there is a datepicker to select the date of birth where when the user enters a dateo f birth the month has to be substracted from the year and the value has to be again added till it reach a single digit ... i did some code please check if it correct or no...when I checked it is not working out.. If anyone knows pls help...
sum5=getSum4(tv3.getText().toString());
i.putExtra("name4", sum5 + "");
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
String date=Integer.toString(arg3);
String month=Integer.toString(arg2);
String year=Integer.toString(arg1);
tv3.setText(year + month+1);
}
});}
}
public long getSum4(String text)
{
// TODO Auto-generated method stub
long sum5 = 0;
char[] name4 = new char[text.length()];
name4 = text.toCharArray();
for(int i=0; i<text.length(); i++)
{
sum5 -= value4( name4[i] );
}
while (sum5>9)
{
sum5 = findDigitSum(sum5);
}
return sum5;
}
public long findDigitSum4(long n)
{
int sum5 = 0;
while (n != 0)
{
sum5 += n % 10;
n = n / 10;
}
return sum5;
}
private int value4(char a) {
// TODO Auto-generated method stub
switch(a) {
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 1;
}
}
}
Upvotes: 1
Views: 91
Reputation: 1135
You can use three edittexts and and take the value for year and month seperately. then substract it from the year value ..then use your code to make into a single digit
Upvotes: 1