Android data storage and retrieving
I developed an android application in which ... 6 edit texts are there for
collecting the details of the user... like first name, lastname, middle
name, mobile number email id etc... what I need is when user gives this
details and press the save button.. the details has to store.. and the
user has to retrieve this data when the recall button is pressed ... so
what I have to do for it... I am giving the code that I did ... pls check
and suggest me what I have to do next...
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DatePicker date = (DatePicker) findViewById (R.id.datePicker1);
final TextView tv1 = (TextView) findViewById (R.id.textView88);
final TextView tv2 = (TextView) findViewById (R.id.textView89);
final TextView tv3 = (TextView) findViewById (R.id.textView90);
final TextView tv4 = (TextView) findViewById (R.id.textView91);
final TextView tv5 = (TextView) findViewById (R.id.textView92);
final TextView tv6 = (TextView) findViewById (R.id.textView93);
final TextView tv7 = (TextView) findViewById (R.id.textView94);
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);
tv1.setText(date+ month+1 +year);
tv2.setText(month+1 + date);
tv3.setText(year);
tv4.setText(month+1);
tv5.setText(date);
tv6.setText(date + year);
}
});}
public void sum(View v)
{
long sum1=0;
long sum2=0;
long sum3=0;
long sum4=0;
long sum5=0;
long sum6=0;
long sum7=0;
long sum8=0;
long sum=0;
long sum11=0;
long sum12=0;
long sum13=0;
long sum14=0;
long sum100=0;
EditText et1 = (EditText) findViewById (R.id.editText1);
EditText et2 = (EditText) findViewById (R.id.editText2);
EditText et3 = (EditText) findViewById (R.id.editText3);
EditText et4 = (EditText) findViewById (R.id.editText4);
EditText et5 = (EditText) findViewById (R.id.editText5);
EditText et6 = (EditText) findViewById (R.id.editText6);
final DatePicker date = (DatePicker) findViewById (R.id.datePicker1);
final TextView tv1 = (TextView) findViewById (R.id.textView88);
final TextView tv2 = (TextView) findViewById (R.id.textView89);
final TextView tv3 = (TextView) findViewById (R.id.textView90);
final TextView tv4 = (TextView) findViewById (R.id.textView91);
final TextView tv5 = (TextView) findViewById (R.id.textView92);
final TextView tv6 = (TextView) findViewById (R.id.textView93);
final TextView tv7 = (TextView) findViewById (R.id.textView94);
sum1=getSum(et1.getText().toString() + et2.getText().toString() +
et3.getText().toString() + et4.getText().toString());
sum2=getSum1(et1.getText().toString() + et2.getText().toString() +
et3.getText().toString() + et4.getText().toString());
sum3=getSum2(tv1.getText().toString());
/*sum4=getSum3(tv2.getText().toString());*/
sum5=getSum4(tv3.getText().toString());
sum6=getSum5(tv4.getText().toString());
sum8=getSum7(tv5.getText().toString());
String yearf = tv3.getText().toString();
int yearb = Integer.valueOf(yearf);
int val = 2013 - yearb;
long val1 = sum3;
/*int val2 = Integer.valueOf(val1);*/
long val3 = 36 - val1;
int val4 = 9;
long val5 = val3 + val4;
long val6 = val5 + val4;
long val7 = val6 + 50;
sum = getSum3(tv2.getText().toString()) +
getSum8(tv6.getText().toString());
sum100 = getSum4(tv3.getText().toString()) +
getSum5(tv4.getText().toString());
if (val <= val3)
{
sum4=getSum3(tv2.getText().toString());
}
else if ((val <= val5) && (val > val3))
{
sum4=getSum8(tv6.getText().toString());
}
else if ((val<=val6) && (val > val5) && (val > val3))
{
/*sum = getSum3(tv2.getText().toString()) +
getSum8(tv6.getText().toString());*/
sum4=getSum9(Integer.toString((int) sum));
}
else
{
sum4=getSum9(Integer.toString((int) sum100));
}
if (val <= val3)
{
if (sum8>sum6)
{
sum7 = (sum8 - sum6);
}
else
{
sum7 = (sum6 - sum8);
}
}
else if ((val <= val5) && (val > val3))
{
if(sum5>sum8)
{
sum7=(sum5 - sum8);
}
else
{
sum7 = (sum8 - sum5);
}
}
else if ((val<=val6) && (val > val5) && (val > val3))
{
sum11 = (sum5 - sum8);
sum12 = (sum8 - sum5);
sum13 = (sum6 - sum8);
sum14 = (sum8 - sum6);
if ((sum11 > sum12) && (sum13 > sum14))
{
if (sum11 > sum13)
{
sum7 = sum11 - sum13;
}
else
{
sum7 = sum13 - sum11;
}
}
else if ((sum12 > sum11) && (sum13 > sum14))
{
if (sum12 > sum13)
{
sum7 = sum12 - sum13;
}
else
{
sum7 = sum13 - sum12;
}
}
else if ((sum11 > sum12) && (sum14 > sum13))
{
if (sum11 > sum14)
{
sum7 = sum11 - sum14;
}
else
{
sum7 = sum14 - sum11;
}
}
else if ((sum12 > sum11) && (sum14 > sum13))
{
if (sum12 > sum14)
{
sum7 = sum12 - sum14;
}
else
{
sum7 = sum14 - sum12;
}
}
}
else
{
if (sum5>sum6)
{
sum7 = (sum5 - sum6);
}
else
{
sum7 = (sum6 - sum5);
}
}
String edtxt1 = et1.getText().toString();
String edtxt4 = et4.getText().toString();
String edtxt5 = et5.getText().toString();
String edtxt6 = et6.getText().toString();
if(edtxt1.equals(""))
{
Toast.makeText(getApplicationContext(),"First Name should not
be left blank, Please enter your First Name ",
Toast.LENGTH_LONG).show();
}
else if(edtxt4.equals(""))
{
Toast.makeText(getApplicationContext(),"Last Name should not
be left blank, Please enter your Last Name ",
Toast.LENGTH_LONG).show();
}
else if(edtxt5.equals(""))
{
Toast.makeText(getApplicationContext(),"Mobile Number should
not be left blank, Please enter your Mobile Number ",
Toast.LENGTH_LONG).show();
}
else if(edtxt6.equals(""))
{
Toast.makeText(getApplicationContext(),"E-Mail id should not
be left blank, Please enter your E-Mail id ",
Toast.LENGTH_LONG).show();
}
else{
Intent i = new Intent(this, result.class);
i.putExtra("name", sum1 + "");
i.putExtra("name1", sum2 + "");
i.putExtra("name2", sum3 + "");
i.putExtra("name3", sum4 + "");
i.putExtra("name4", sum7 + "");
startActivity(i);
}
public long getSum(String text)
{
// TODO Auto-generated method stub
long sum1 = 0;
char[] name = new char[text.length()];
name = text.toCharArray();
for(int i=0; i<text.length(); i++)
{
sum1 += value( name[i] );
}
while (sum1>9)
{
sum1 = findDigitSum(sum1);
}
return sum1;
}
public long getSum1(String text)
{
// TODO Auto-generated method stub
long sum2 = 0;
char[] name1 = new char[text.length()];
name1 = text.toCharArray();
for(int i=0; i<text.length(); i++)
{
sum2 += value1( name1[i] );
}
while (sum2>9)
{
sum2 = findDigitSum(sum2);
}
return sum2;
}
No comments:
Post a Comment