在我的Android应用程序中,我有一个View类,它将在按钮点击时激活..但我需要调用另一个方法,它使用if else语句,我必须做什么...?
我检查了
class name().execute();
执行,但它只适用于班级...我在下面给出我的代码.. 在xml中
android:onClick : "save"
活动
public void save(View V)
{
//code
}
我需要使用if else语句
调用此方法像
SharedPreferences setting = getSharedPreferences(PREFS_NAME, 0);
if (setting.getString("log", "").toString().equals("log"))
{
// call the above method
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.fullexplanationentry_xm);
SharedPreferences setting = getSharedPreferences(PREFS_NAME, 0);
if (setting.getString("log", "").toString().equals("log"))
{
//Here I need call the save method..
}
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);
EditText et7 = (EditText) findViewById (R.id.editText7);
EditText et8 = (EditText) findViewById (R.id.editText8);
EditText et9 = (EditText) findViewById (R.id.editText9);
et1.setText(getIntent().getStringExtra("ett1"));
et2.setText(getIntent().getStringExtra("ett2"));
et3.setText(getIntent().getStringExtra("ett3"));
et4.setText(getIntent().getStringExtra("ett4"));
et5.setText(getIntent().getStringExtra("ett5"));
et6.setText(getIntent().getStringExtra("ett6"));
et7.setText(getIntent().getStringExtra("ett7"));
et8.setText(getIntent().getStringExtra("ett8"));
et9.setText(getIntent().getStringExtra("ett9"));
db = openOrCreateDatabase("MyDBI", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS DATA (fname VARCHAR, mname VARCHAR,lname VARCHAR,cfname VARCHAR, cmname VARCHAR,clname VARCHAR,bday NUMERIC,bmonth NUMERIC,byear NUMERIC);");
}
public void save(View V)
{
long sum1 = 0;
long sum2 = 0;
long sum3 = 0;
long sum7 = 0;
long sum8 = 0;
long sum9 = 0;
sum10 = 0;
sum11 = 0;
sum12 = 0;
sum13 = 0;
long sum14 = 0;
long sum15 = 0;
long sum16 = 0;
long sum17 = 0;
sum18 = 0;
sum19 = 0;
sum20 = 0;
long sum22 = 0;
long sum23 = 0;
long sum24 = 0;
long sum25 = 0;
sum70 = 0;
sum80 = 0;
sum90 = 0;
//Destiny Number Karmic Debt
long kar1 = 0;
long kar2 = 0;
long kar3 = 0;
long kar7 = 0;
//Heart Number Karmic Debt
long kar4 = 0;
long kar5 = 0;
long kar6 = 0;
long kar8 = 0;
//Talent Number Karmic Debt
//long kar9 = 0;
long kar10 = 0;
long kar11 = 0;
//Personality Number Karmic Debt
long kar12 = 0;
long kar13 = 0;
long kar14 = 0;
long kar15 = 0;
//Minor expression Number Karmic Debt
long kar16 = 0;
long kar17 = 0;
long kar18 = 0;
long kar19 = 0;
//Minor Heart Desire Number Karmic Debt
long kar20 = 0;
long kar21 = 0;
long kar22 = 0;
long kar23 = 0;
//Minor Personality Number Karmic Debt
long kar24 = 0;
long kar25 = 0;
long kar26 = 0;
long kar27 = 0;
//Balance Number Karmic Debt
long kar28 = 0;
//year now to single digit
long yearnow = 0;
//month now to single digit
long monthnow = 0;
//Day now to single digit
long daynow = 0;
long ch = 0;
long ch1 = 0;
long ch2 = 0;
long ch4 = 0;
long ch3 = 0;
long pin1 = 0;
long pin2 = 0;
long pin3 = 0;
long pin4 = 0;
long pin = 0;
long br1 = 0;
long br2 = 0;
long br3 = 0;
long a =0;
int yearat =0;
int monthat = 0;
int dayat = 0;
GregorianCalendar gc = new GregorianCalendar();
yearat = gc.get(Calendar.YEAR);
yearstr = Integer.toString(yearat);
monthat = gc.get(Calendar.MONTH) + 1;
monthstr = Integer.toString(monthat);
dayat = gc.get(Calendar.DAY_OF_MONTH);
daystr = Integer.toString(dayat);
List<Integer> sum21;
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);
EditText et7 = (EditText) findViewById (R.id.editText7);
EditText et8 = (EditText) findViewById (R.id.editText8);
EditText et9 = (EditText) findViewById (R.id.editText9);
sum1 = getSum1(et1.getText().toString());
sum2 = getSum2(et2.getText().toString());
sum3 = getSum3(et3.getText().toString());
sum7 = getSum7(et7.getText().toString());
sum8 = getSum8(et8.getText().toString());
sum9 = getSum9(et9.getText().toString());
sum11 = getSum11((et7.getText().toString()) + (et8.getText().toString()) + (et9.getText().toString()));
sum12 = getSum12(et1.getText().toString() + et2.getText().toString() + et3.getText().toString());
sum13 = getSum13(et1.getText().toString() + et2.getText().toString() + et3.getText().toString());
sum14 = getSum14(et4.getText().toString() + et5.getText().toString() + et6.getText().toString());
sum15 = getSum15(et4.getText().toString() + et5.getText().toString() + et6.getText().toString());
sum16 = getSum16(et4.getText().toString() + et5.getText().toString() + et6.getText().toString());
sum18 = getSum18((yearstr) + (et7.getText().toString() + et8.getText().toString()));
sum19 = getSum19((monthstr) + (sum18));
sum20 = getSum20((daystr) + sum19);
sum21 = getMissingNo(et1.getText().toString() + et2.getText().toString() + et3.getText().toString());
//Destiny Numberkarmic debt
kar1 = getKar1(et1.getText().toString());
kar2 = getKar2(et2.getText().toString());
kar3 = getKar3(et3.getText().toString());
kar7 = getKar7(et1.getText().toString() + et2.getText().toString() + et3.getText().toString());
//Heart Number karmic debt
kar4 = getKar4(et1.getText().toString());
kar5 = getKar5(et2.getText().toString());
kar6 = getKar6(et3.getText().toString());
kar8 = getKar8(et1.getText().toString() + et2.getText().toString() + et3.getText().toString());
//Talent Number Karmic Debt
//kar9 = getKar9(et7.getText().toString());
kar10 = getKar10(et9.getText().toString());
kar11 = getKar11(et7.getText().toString() + et8.getText().toString() + et9.getText().toString());
//Personality Number karmic Debt
kar12 = getKar12(et1.getText().toString());
kar13 = getKar13(et2.getText().toString());
kar14 = getKar14(et3.getText().toString());
kar15 = getKar15(et1.getText().toString() + et2.getText().toString() + et3.getText().toString());
//Minor Expression Number Karmic Debt Calculation
kar16 = getKar16(et4.getText().toString());
kar17 = getKar17(et5.getText().toString());
kar18 = getKar18(et6.getText().toString());
kar19 = getKar19(et4.getText().toString() + et5.getText().toString() + et6.getText().toString());
//Minor Heart Desire Number karmic debt
kar20 = getKar20(et4.getText().toString());
kar21 = getKar21(et5.getText().toString());
kar22 = getKar22(et6.getText().toString());
kar23 = getKar23(et4.getText().toString() + et5.getText().toString() + et6.getText().toString());
//Minor Personality Number karmic Debt
kar24 = getKar24(et4.getText().toString());
kar25 = getKar25(et5.getText().toString());
kar26 = getKar26(et6.getText().toString());
kar27 = getKar27(et4.getText().toString() + et5.getText().toString() + et6.getText().toString());
//First Pinnacle Karmic Debt
sum70 = getsum70(et7.getText().toString());
sum80 = getSum80(et8.getText().toString());
sum90 = getSum90(et9.getText().toString());
sum10 = getSum10 ((et1.getText().toString()) + (et2.getText().toString()) + (et3.getText().toString()));
pin1 = getSumpin1(Integer.toString((int)sum70) + Integer.toString((int) sum80));
pin2 = getSumpin2(Integer.toString((int)sum70) + Integer.toString((int)sum90));
pin3 = getSumpin3(Integer.toString((int)pin1) + Integer.toString((int)pin2));
pin4 = getSumpin4(Integer.toString((int)sum80) + Integer.toString((int)sum90));
String firstName = et1.getText().toString();
String middleName = et2.getText().toString();
String lastName = et3.getText().toString();
String callFirstName = et4.getText().toString();
String dates = et7.getText().toString();
String months = et8.getText().toString();
String years = et9.getText().toString();
String aChar3 = "";
if(firstName.trim().length()>0)
{
aChar3 = firstName.substring(0,1);
}
String aChar4 = "";
if(middleName.trim().length()>0)
{
aChar4 = middleName.substring(0,1);
}
String aChar5 = "";
if (lastName.trim().length()>0)
{
aChar5 = lastName.substring(0,1);
}
StringBuilder sb = new StringBuilder();
sb.append(aChar3);
sb.append(aChar4);
sb.append(aChar5);
String aChar6 = sb.toString();
sum22 = getSum22(String.valueOf(aChar6));
//Balance Number Karmic Debt
kar28 = getKar28(String.valueOf(aChar6));
char aChar = firstName.charAt(0);
int strLength = firstName.length();
char aChar1 = firstName.charAt(strLength-1);
char aChar2 = gReport1(V); // Please check here ..I think the problem s here
int itemCount =9 - sum21.size();
sum23 = getSum23(String.valueOf(aChar1));
sum24 = getSum24(String.valueOf(aChar));
sum25 = getSum25(String.valueOf(aChar2));
//GregorianCalendar gc = new GregorianCalendar();
//int yearat = gc.get(Calendar.YEAR);
int day1 = Integer.parseInt(et7.getText().toString());
int month1 = Integer.parseInt(et8.getText().toString());
int year1 = Integer.parseInt(et9.getText().toString());
String s1 = String.valueOf(FullExplanationEntry.this.getAge(year1, month1, day1));
int val = 0;
long val1 = sum11;
//long val = sum16;
val = Integer.valueOf(s1);
long val2 = 36 - val1;
int val4 = 9;
long val5 = val2 + val4;
long val6 = val5 + val4;
long val7 = val6 + 80;
long val18 = val2 + 1;
long val19 = val5 + 1;
long val20 = val6 + 1;
long pYear = 0;
if (sum70 > sum80)
{
ch1 = (sum70 - sum80);
}
else
{
ch1 = (sum80 - sum70);
}
if (sum70 > sum90)
{
ch2 = (sum70 - sum90);
}
else
{
ch2 = (sum90 - sum70);
}
if (sum80 > sum90)
{
ch4 = (sum80 - sum90);
}
else
{
ch4 = (sum90 - sum80);
}
if (ch1 > ch2)
{
ch3 = ch1 - ch2;
}
else
{
ch3 = ch2 - ch1;
}
if (val <= val2)
{
ch = ch1;
}
else if ((val > val2) && (val <= val5))
{
ch = ch2;
}
else if ((val > val2) && (val> val5) && (val <= val6))
{
ch = ch3;
}
else if ((val > val2) && (val> val5) && (val > val6) && (val<= val7))
{
ch = ch4;
}
if (val <= val2)
{
pin = pin1;
}
else if ((val > val2) && (val <= val5))
{
pin = pin2;
}
else if ((val > val2) && (val> val5) && (val <= val6))
{
pin = pin3;
}
else if ((val > val2) && (val> val5) && (val > val6) && (val<= val7))
{
pin = pin4;
}
if (sum11 > sum10)
{
br1 = sum11 - sum10;
}
else
{
br1 = sum10 - sum11;
}
if(sum12 > sum13)
{
br2 = sum12 - sum13;
}
else
{
br2 = sum13 - sum12;
}
if(sum10 > sum12)
{
br3 = sum10 - sum12;
}
else
{
br3 = sum12 - sum10;
}
int dayS = Integer.parseInt(et7.getText().toString());
int monthS = Integer.parseInt(et8.getText().toString());
int yearS = Integer.parseInt(et9.getText().toString());
yearnow = getSumYear(String.valueOf(yearat));
monthnow = getSumMonth(String.valueOf(monthat));
daynow = getSumDay(String.valueOf(dayat));
//pYear = getKarPyar(String.valueOf(yearat));
//Karmic Debt Pinnacle
int karPin1 = 0;
long karPin2 = 0;
long karPin3 = 0;
int karPin4 = 0;
//Karmic day
int karDay = 0;
long karYear = 0;
//Karmic Debt Personal Year
long karPyr = 0;
long karPmn = 0;
long karPdy = 0;
int kPin1 = Integer.parseInt(et7.getText().toString()) + Integer.parseInt(et8.getText().toString());
long kPin2 = sum9 + Integer.parseInt(et7.getText().toString());
long kPin3 = pin1 + pin2;
long kPin4 = sum9 + Integer.parseInt(et8.getText().toString());
long kPyr = yearnow + kPin1;
long kPmn = monthnow + kPyr;
long kPdy = daynow + kPmn;
karYear = getKarYear(String.valueOf(yearnow));
//Karmic Debt First Pinnacle
if(kPin1 == 13)
{
karPin1 = 13;
}
else if(kPin1 == 14)
{
karPin1 = 14;
}
else if(kPin1 == 16)
{
karPin1 = 16;
}
else if(kPin1 == 19)
{
karPin1 = 19;
}
else
{
karPin1 = 0;
}
//Karmic Debt Pinnacle 2
if(kPin2 == 13)
{
karPin2 = 13;
}
else if(kPin2 == 14)
{
karPin2 = 14;
}
else if(kPin2 == 16)
{
karPin2 = 16;
}
else if(kPin2 == 19)
{
karPin2 = 19;
}
else
{
karPin2 = 0;
}
//Karmic Debt Pinnacle 3
if(kPin3 == 13)
{
karPin3 = 13;
}
else if(kPin3 == 14)
{
karPin3 = 14;
}
else if(kPin3 == 16)
{
karPin3 = 16;
}
else if(kPin3 == 19)
{
karPin3 = 19;
}
else
{
karPin3 = 0;
}
//Karmic Debt Pinnacle 4
if(kPin4 == 13)
{
karPin4 = 13;
}
else if(kPin4 == 14)
{
karPin4 = 14;
}
else if(kPin4 == 16)
{
karPin4 = 16;
}
else if(kPin4 == 19)
{
karPin4 = 19;
}
else
{
karPin4 = 0;
}
//Karmic Debt Personal Year No
if(kPyr == 13)
{
karPyr = 13;
}
else if(kPyr == 14)
{
karPyr = 14;
}
else if(kPyr == 16)
{
karPyr = 16;
}
else if(kPyr == 19)
{
karPyr = 19;
}
else
{
karPyr = 0;
}
//Karmic Debt Personal Month No
if(kPmn == 13)
{
karPmn = 13;
}
else if(kPmn == 14)
{
karPmn = 14;
}
else if(kPmn == 16)
{
karPmn = 16;
}
else if(kPmn == 19)
{
karPmn = 19;
}
else
{
karPmn = 0;
}
//Karmic Debt Personal Day No
if(kPdy == 13)
{
karPdy = 13;
}
else if(kPdy == 14)
{
karPdy = 14;
}
else if(kPdy == 16)
{
karPdy = 16;
}
else if(kPdy== 19)
{
karPdy = 19;
}
else
{
karPdy = 0;
}
//Karmic Debt day
if(dayS == 13)
{
karDay = 13;
}
else if(dayS == 14)
{
karDay = 14;
}
else if(dayS == 16)
{
karDay = 16;
}
else if(dayS == 19)
{
karDay = 19;
}
else
{
karDay = 0;
}
if(firstName.equals(""))
{
Toast.makeText(getApplicationContext(), "First Name should not be left blank.. Please enter your First Name and try once again.", Toast.LENGTH_LONG).show();
return;
}
else if(lastName.equals(""))
{
Toast.makeText(getApplicationContext(), "Last Name should not be left blank.. Please enter your Last Name and try once again.", Toast.LENGTH_LONG).show();
return;
}
else if(callFirstName.equals(""))
{
Toast.makeText(getApplicationContext(), "Please enter your First Name that is currently used and try once again.", Toast.LENGTH_LONG).show();
return;
}
else
{
/*SharedPreferences setting = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editors = setting.edit();
editors.putString("log", "log");
editors.commit();*/
SharedPreferences setting = this.getSharedPreferences(PREFS_NAME,0);
SharedPreferences.Editor editors = setting.edit();
editors.putString("log", "log");
// editors.putLong("name18",sum18);
// editors.putLong("name19",sum19);
// editors.putLong("name20",sum20);
// editors.putLong("pin",pin);
// editors.putLong("ch",ch);
// editors.putString("log", "log");
// editors.putString("yearstr",yearstr);
// editors.putString("monthstr",monthstr);
// editors.putString("daystr",daystr);
editors.commit();
Intent i = new Intent(FullExplanationEntry.this, TabLayoutActivity.class);
//Intent i = new Intent(this, FullExplanation.class);
//Intent i = new Intent(this, SecondResult.class);
//Personal Year
i.putExtra("name18",sum18 + "");
//Personal Month
i.putExtra("name19",sum19 + "");
//Personal Dya
i.putExtra("name20",sum20 + "");
//Current Pinnacle
i.putExtra("pin", pin + "");
//Current Challenge
i.putExtra("ch", ch + "");
i.putExtra("yearstr", yearstr);
i.putExtra("monthstr", monthstr);
i.putExtra("daystr", daystr);
startActivity(i);
/* int day = Integer.parseInt(et7.getText().toString());
int month = Integer.parseInt(et8.getText().toString());
int year = Integer.parseInt(et9.getText().toString());
String s = String.valueOf(FullExplanationEntry.this.getAge(year, month, day));
int age = getAge(year, month, day);
// int sum17 = getSum17(firstName, age);
//Destiny number
i.putExtra("name10", sum10 + "");
//Telent Number
i.putExtra("name11", sum11 + "");
//Heart Desire Number
i.putExtra("name12", sum12 + "");
//Personality Number
i.putExtra("name13", sum13 + "");
//Minor Expression Number
i.putExtra("name14", sum14 + "");
//Minor Heart Desire Number
i.putExtra("name15", sum15 + "");
//Minor Personality Number
i.putExtra("name16", sum16 + "");
i.putExtra("name17", sum17 + "");
//First Challenge
i.putExtra("val2", val2 + "");
//Second Challenge
i.putExtra("val5", val5 + "");
//Thiurd Challenge
i.putExtra("val6", val6 + "");
//Fourth Challenge
i.putExtra("val7", val7 + "");
i.putExtra("val18", val18 + "");
i.putExtra("val19", val19 + "");
i.putExtra("val20", val20 + "");
i.putExtra("name17", sum17 + "");
//Current Challenge
i.putExtra("ch", ch + "");
//Challenge Numbers
i.putExtra("ch1", ch1 + "");
i.putExtra("ch2", ch2 + "");
i.putExtra("ch3", ch3 + "");
i.putExtra("ch4", ch4 + "");
//age
i.putExtra("a", s + "");
//Pinnacle
//First Pinnacle
i.putExtra("namepin1", pin1 + "");
//Second Pinnacle
i.putExtra("namepin2", pin2 + "");
//Third Pinnacle
i.putExtra("namepin3", pin3 + "");
//Fourth Pinnacle
i.putExtra("namepin4", pin4 + "");
//Current Pinnacle
i.putExtra("pin", pin + "");
//Special Letters
i.putExtra("aChar", aChar + "");
i.putExtra("aChar1", aChar1 + "");
i.putExtra("aChar2",aChar2+ "");
//Bridge Numbers.
i.putExtra("br1", br1 + "");
i.putExtra("br2", br2+ "");
i.putExtra("br3",br3+ "");
//Relational Thought Number
i.putExtra("name1",sum1 + "");
//Personal Year Number
i.putExtra("name18",sum18 + "");
//Personal Month Number
i.putExtra("name19",sum19 + "");
//Personal Day Number
i.putExtra("name20",sum20 + "");
//Relational thought Number
i.putExtra("itemCount",itemCount + "");
//Karmic Lessonbs
i.putIntegerArrayListExtra("sum21", (ArrayList<Integer>) sum21);
// Balance Number
i.putExtra("name22",sum22 + "");
//Cap Stone
i.putExtra("name23",sum23 + "");
//Corner Stone
i.putExtra("name24",sum24 + "");
//First vowel
i.putExtra("name25",sum25 + "");
//Destiny number karmic debt FML Full
i.putExtra("karmi1",kar1 + "");
i.putExtra("karmi2",kar2 + "");
i.putExtra("karmi3",kar3 + "");
i.putExtra("karmi7",kar7 + "");
//Heart Number Karmic Debt FML Full
i.putExtra("karmi4",kar4 + "");
i.putExtra("karmi5",kar5 + "");
i.putExtra("karmi6",kar6 + "");
i.putExtra("karmi8",kar8 + "");
//Talent Number Karmic Debt DY Full
//i.putExtra("kar9",kar9 + "");
i.putExtra("karmi10",kar10 + "");
i.putExtra("karmi11",kar11 + "");
//Personality Number Karmic Debt FML Full
//Heart Number Karmic Debt FML Full
i.putExtra("karmi12",kar12 + "");
i.putExtra("karmi13",kar13 + "");
i.putExtra("karmi14",kar14 + "");
i.putExtra("karmi15",kar15 + "");
//Minor Expression Number Karmic Debt FML Full
i.putExtra("karmi16",kar16 + "");
i.putExtra("karmi17",kar17 + "");
i.putExtra("karmi18",kar18 + "");
i.putExtra("karmi19",kar19 + "");
//Minor Heart Desire Number Karmic Debt FML Full
i.putExtra("karmi20",kar20 + "");
i.putExtra("karmi21",kar21 + "");
i.putExtra("karmi22",kar22 + "");
i.putExtra("karmi23",kar23 + "");
//Minor Personality Number Karmic Debt FML Full
i.putExtra("karmi24",kar24 + "");
i.putExtra("karmi25",kar25 + "");
i.putExtra("karmi26",kar26 + "");
i.putExtra("karmi27",kar27 + "");
//Balance Number Karmic Debt
i.putExtra("karmi28",kar28 + "");
//Birth Day Karmic Debt
i.putExtra("karPin1",karPin1 + "");
i.putExtra("karPin2",karPin2 + "");
i.putExtra("karPin3",karPin3 + "");
i.putExtra("karPin4",karPin4 + "");
//Persobnal year karmic debt
//Personal year Karmic Debt
i.putExtra("karPyr",karPyr + "");
//Personal Month Karmic Debt
i.putExtra("karPmn",karPmn + "");
//Karmic Debt Personal Day
i.putExtra("karPdy",karPdy + "");
//Current day Karmic Debt
i.putExtra("karDay",karDay + "");
//Current Universla Year
i.putExtra("karyr29",karYear + "");
// startActivity(i);*/
}
}
}
答案 0 :(得分:0)
像这样称呼
SharedPreferences setting = getSharedPreferences(PREFS_NAME, 0);
if (setting.getString("log", "").toString().equals("log")) {
// someView is just an example of a view's id. You will need to change that
// to the id of the view you want to go into your save method.
// The id is defined in your xml file.
View v = findViewById(R.id.someView);
save(v);
}