Android的问题:能解释一下else里边的onBackPressed()方法是返回到哪里去吗?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android的问题:能解释一下else里边的onBackPressed()方法是返回到哪里去吗?相关的知识,希望对你有一定的参考价值。
public boolean onKeyDown(int keyCode, KeyEvent event)
if (checkNetWorkStatus())
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack())
webView.goBack(); // goBack()表示返回WebView的上一页面
return true;
else
onBackPressed();
return super.onKeyDown(keyCode, event);
/**
* Called when the activity has detected the user's press of the back
* key. The default implementation simply finishes the current activity,
* but you can override this to do whatever you want.
*/
public void onBackPressed()
if (mActionBar != null && mActionBar.collapseActionView())
return;
if (!mFragments.popBackStackImmediate())
finishAfterTransition();
/**
* Reverses the Activity Scene entry Transition and triggers the calling Activity
* to reverse its exit Transition. When the exit Transition completes,
* @link #finish() is called. If no entry Transition was used, finish() is called
* immediately and the Activity exit Transition is run.
* @see android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, android.util.Pair[])
*/
public void finishAfterTransition()
if (!mActivityTransitionState.startExitBackTransition(this))
finish();
追问
……看不懂
追答。。。。。。。。。。。。。这么简单哪里看不懂。。。。
追问……就是还是没弄懂它返回到哪个页面的
追答返回上一个喽, webview内部还需要解决 http://blog.csdn.net/t12x3456/article/details/39134961
本回答被提问者和网友采纳 参考技术B 此次擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦擦我的代码出错了,谁能解释一下怎么回事?
【中文标题】我的代码出错了,谁能解释一下怎么回事?【英文标题】:Error in my code, can anyone explain whats wrong? 【发布时间】:2014-03-21 00:44:20 【问题描述】:我是 C++ 新手,我正在开发一个程序,但在第 39 行它显示错误“else”,没有先前的“if”,但我确实有一个先前的 if。有人对我做错了什么有任何意见吗?这是我的程序代码。谢谢。
1 #include <fstream>
2 #include <iostream>
3 #include <cstdlib>
4 using namespace std;
5 int main()
6
7 //Declarations
8 ifstream masterFile;
9 ifstream transactionFile;
10 ofstream newMasterFile;
11 double mClientNumber, mtotalClientCost, tClientNumber, titemClientCost;
12 string mClientfName, mClientlName;
13 cout << "Master File Updating Starting" ;
14 masterFile.open("Master.rtf");
15 transactionFile.open("Transaction.rtf");
16 newMasterFile.open("newMaster.rtf");
17 masterFile >> mClientNumber;
18 masterFile >> mClientfName;
19 masterFile >> mClientlName;
20 masterFile >> mtotalClientCost;
21 transactionFile >> tClientNumber;
22 transactionFile >>titemClientCost;
23 while ( transactionFile.eof() )
24
25 while (( masterFile.eof()) && (mClientNumber < tClientNumber))
26
27 newMasterFile << mClientNumber << endl;
28 newMasterFile << mClientfName << endl;
29 newMasterFile << mClientlName << endl;
30 newMasterFile << mtotalClientCost << endl;
31 masterFile >> mClientNumber;
32 masterFile >> mClientfName;
33 masterFile >> mClientlName;
34 masterFile >> mtotalClientCost;
35
36 if (masterFile.eof());
37
38 cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
39 else if (mClientNumber == tClientNumber);
40 mtotalClientCost = mtotalClientCost + titemClientCost;
41 newMasterFile << mClientNumber << endl;
42 newMasterFile << mClientfName << endl;
43 newMasterFile << mClientlName << endl;
44 newMasterFile << mtotalClientCost << endl;
45 masterFile >> mClientNumber;
46 masterFile >> mClientfName;
47 masterFile >> mClientlName;
48 masterFile >> mtotalClientCost;
49 else if (mClientNumber > tClientNumber);
50 cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
51
52 transactionFile >> tClientNumber;
53 transactionFile >> titemClientCost;
54
55 while (masterFile.eof())
56
57 newMasterFile << mClientNumber << endl;
58 newMasterFile << mClientfName << endl;
59 newMasterFile << mClientlName << endl;
60 newMasterFile << mtotalClientCost << endl;
61 masterFile >> mClientNumber;
62 masterFile >> mClientfName;
63 masterFile >> mClientlName;
64 masterFile >> mtotalClientCost;
65
66 cout << "Master File Updating Complete" ;
67
68 masterFile.close();
69 transactionFile.close();
70 newMasterFile.close();
71
72 system("pause");
73 return 0;
74
【问题讨论】:
这不是你的问题,但你可能会觉得这很有趣***.com/questions/5605125/… 【参考方案1】:if (masterFile.eof());
//^^this ; here effectively terminates your if block and
//does not have a closing before else
类似的问题可以在这里找到:
if (mClientNumber == tClientNumber);
//^^another line below same problem
【讨论】:
分号是多余的。它终止 if 语句。 @sj0h 是的,确切地说。我会更新措辞,谢谢!【参考方案2】:在所有 if 语句中,您添加了一个不必要的 ;
。
if (masterFile.eof());
// ^ this semicolon is not supposed to be there
;
将终止 if 语句。
改为这样做:
if (masterFile.eof())
此外,您没有关闭 if 语句中的第一个括号。所以最终的产品应该是这样的:
if (masterFile.eof())
//if body
else if (*next condition*)
//else if body
等等..干杯
【讨论】:
【参考方案3】:首先你在 if 和 else if 语句之后放置了一个分号
if (masterFile.eof());
else if (mClientNumber == tClientNumber);
替换它们。
如果不考虑这个错字 yjen,else if 没有前面的 if 语句。相反,它被放入封闭 if 语句的复合语句中
if (masterFile.eof());
cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
else if (mClientNumber == tClientNumber);
也许你的意思是以下
if (masterFile.eof());
cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
else if (mClientNumber == tClientNumber);
或者
if (masterFile.eof());
cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
if (mClientNumber == tClientNumber);
【讨论】:
【参考方案4】:您在少数地方忘记了 和
。将第 36-51 行更改为
36 if (masterFile.eof())
37
38 cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
39 else if (mClientNumber == tClientNumber)
40 mtotalClientCost = mtotalClientCost + titemClientCost;
41 newMasterFile << mClientNumber << endl;
42 newMasterFile << mClientfName << endl;
43 newMasterFile << mClientlName << endl;
44 newMasterFile << mtotalClientCost << endl;
45 masterFile >> mClientNumber;
46 masterFile >> mClientfName;
47 masterFile >> mClientlName;
48 masterFile >> mtotalClientCost;
49 else if (mClientNumber > tClientNumber)
50 cout << "Error Client ID: " << tClientNumber << " not in Master File." ;
51
【讨论】:
您忘记提及他/她将;
放置在错误的位置并终止了 if 语句。以上是关于Android的问题:能解释一下else里边的onBackPressed()方法是返回到哪里去吗?的主要内容,如果未能解决你的问题,请参考以下文章