Tablelayout在手机转动时丢失信息(Android)

时间:2012-12-27 09:08:18

标签: android tablelayout

我有一个表格布局,等待信息到达。当数据到达时,我动态填充表格。但当我将手机转动90度时,桌子消失了。 代码:

{
TableRow row;
TextView t1, t2;
ArrayList<InfoPair> values;
values = processResults(r);
Iterator it = values.iterator();

        while (it.hasNext()) {
            InfoPair pairs = (InfoPair) it.next();

            row = new TableRow(c);

            t1 = new TextView(c);
            t2 = new TextView(c);

            // t1.setTextLocale(new Locale("hu", "hu"));

            t1.setText(pairs.getLabel());
            t2.setText(pairs.getValue());

            t1.setWidth(200);
            t2.setWidth(280);

            t1.setBackgroundColor(Color.GRAY);
            t2.setBackgroundColor(Color.YELLOW);

            row.addView(t1);
            row.addView(t2);

            infoTable.addView(row);

            it.remove(); // avoids a ConcurrentModificationException
}

如果我希望桌子保存信息而不是在我打开手机时消失,我该怎么办?

1 个答案:

答案 0 :(得分:0)

最简单的方式

 <activity android:theme="@style/Theme.app" android:configChanges="orientation|screenSize" android:name=".YourActivity" android:label="@string/app_name"></activity>

这是主要的事情android:configChanges="orientation|screenSize"