4 eclipse android screen-orientation
我有一个问题,我需要从数据库中显示数据,并以表格的形式在我的应用程序中查看它.一切顺利,但由于表格列很长(由于从数据库收到的数据),我决定将方向设置为横向以便于查看(我猜).实现此代码后,
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Run Code Online (Sandbox Code Playgroud)
onCreate()函数被调用了两次.我知道它已被调用两次,因为我已经包含了log.i. 我的所有log.i都被调用了两次.我的日志应显示如下:
03-19 14:13:53.401: I/loop check(30510): loop
03-19 14:13:54.112: I/jObjLength(30510): 5
03-19 14:13:54.112: I/JSON(30510): jsonObj = work0
03-19 14:13:54.162: I/JSON(30510): jsonObj = work1
03-19 14:13:54.162: I/JSON(30510): jsonObj = work2
03-19 14:13:54.172: I/JSON(30510): jsonObj = work3
03-19 14:13:54.172: I/JSON(30510): jsonObj = work4
Run Code Online (Sandbox Code Playgroud)
但相反,它显示了这一点:
03-19 14:30:12.801: I/loop check(30510): loop
03-19 14:30:12.921: I/jObjLength(30510): 5
03-19 14:30:12.921: I/JSON(30510): jsonObj = work0
03-19 14:30:12.931: I/JSON(30510): jsonObj = work1
03-19 14:30:12.941: I/JSON(30510): jsonObj = work2
03-19 14:30:12.951: I/JSON(30510): jsonObj = work3
03-19 14:30:12.951: I/JSON(30510): jsonObj = work4
03-19 14:30:12.981: I/loop check(30510): loop
03-19 14:30:13.042: I/jObjLength(30510): 5
03-19 14:30:13.042: I/JSON(30510): jsonObj = work0
03-19 14:30:13.042: I/JSON(30510): jsonObj = work1
03-19 14:30:13.052: I/JSON(30510): jsonObj = work2
03-19 14:30:13.052: I/JSON(30510): jsonObj = work3
03-19 14:30:13.062: I/JSON(30510): jsonObj = work4
Run Code Online (Sandbox Code Playgroud)
这是在我实现setRequestedOrientation之后发生的.任何人都可以解释为什么会发生这种情况以及解决方案的原因是什么.谢谢
继承我的onCreate课程
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Log.i("loop check", "loop");
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_work_listing);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
tblLay = (TableLayout) findViewById(R.id.tblLayout);
jsonParser = new JSONParser();
jObj = jsonParser.getJSONFromUrl(URL);
txtOrderN = new TextView(getApplicationContext());
txtCabinetN = new TextView(getApplicationContext());
txtAssignP = new TextView(getApplicationContext());
txtActualP = new TextView(getApplicationContext());
txtStatS = new TextView(getApplicationContext());
String jsonObj;
for (int i = 0; i < jObj.length(); i++) {
jsonObj = "work";
jsonObj = jsonObj + i;
try {
tblRow = new TableRow(getApplicationContext());
Log.i("JSON", "jsonObj = " + jsonObj);
txtOrderN.setText(jObj.getJSONObject(jsonObj).getString(
"orderN"));
txtCabinetN.setText(jObj.getJSONObject(jsonObj).getString(
"cabinetN"));
txtAssignP.setText(jObj.getJSONObject(jsonObj).getString(
"assignP"));
txtActualP.setText(jObj.getJSONObject(jsonObj).getString(
"actualP"));
txtStatS.setText(jObj.getJSONObject(jsonObj).getString("statS"));
txtOrderN = new TextView(getApplicationContext());
txtCabinetN = new TextView(getApplicationContext());
txtAssignP = new TextView(getApplicationContext());
txtActualP = new TextView(getApplicationContext());
txtStatS = new TextView(getApplicationContext());
tblRow.addView(txtOrderN);
tblRow.addView(txtCabinetN);
tblRow.addView(txtAssignP);
tblRow.addView(txtActualP);
tblRow.addView(txtStatS);
tblLay.addView(tblRow);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error " + e,
Toast.LENGTH_LONG).show();
Log.i("Error ", "" + e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zeta.workorder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.zeta.workorder.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.zeta.workorder.WorkListingActivity"
android:label="@string/title_activity_work_listing" >
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
只需
android:configChanges="keyboardHidden|orientation|screenSize"在<activity>标签中添加属性
来源:Android onCreate()方法在设备旋转时调用两次.(ICS)
| 归档时间: |
|
| 查看次数: |
2541 次 |
| 最近记录: |