我正在通过java为android开发一个应用程序。在我的应用程序中,我通过代码动态创建了一些TableRows。当我旋转或转到另一个活动并返回时,我创建的元素将被清理。为什么?我加
android:configChanges="keyboardHidden|orientation"
我的问题未解决到我的清单文件中。
我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Login"
android:label="@string/title_activity_login" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Mainmenu"
android:label="@string/title_activity_mainmenu" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CustomerList"
android:label="@string/title_activity_customer_list" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SelectProductActivity"
android:configChanges="keyboardHidden|orientation|screensize"
android:label="@string/title_activity_select_product" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我的活动:
公共类 SelectProductActivity 扩展 Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_product);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_select_product, menu);
return true;
}
public void addRow(View v){
TableLayout tbl=(TableLayout)findViewById(R.id.tblProduct);
TableRow row=new TableRow(this);
TableRow.LayoutParams llp = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.WRAP_CONTENT);
llp.setMargins(0,10,0,10);
llp.bottomMargin=20;
row.setLayoutParams(llp);
row.setBackgroundColor(Color.parseColor("#eeeeee"));
//
TextView tv=new TextView(this);
tv.setText("txt1");
tv.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT,.15f ) );
row.addView(tv);
//
EditText ed=new EditText(this);
ed.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT,.15f ) );
row.addView(ed);
//
TextView tv2=new TextView(this);
tv2.setText("txt2");
tv2.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT,.15f ) );
row.addView(tv2);
//
EditText ed2=new EditText(this);
ed2.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT,.15f ) );
row.addView(ed2);
//
TextView tv3=new TextView(this);
tv3.setText("txt3");
tv3.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, .40f ) );
row.addView(tv3);
tbl.addView(row);
}
}