TableRow 布局充气器在横向模式下不显示数据
我有一个奇怪的问题。我正在通过像这样膨胀表行来创建表
TableLayout table = (TableLayout) findViewById(R.id.tablelay);
LayoutInflater inflater = getLayoutInflater();
for (int j = 0; j < limit ; j++) {
TableRow row = (TableRow) inflater.inflate(R.layout.row_details, table, false);
t1 = (TextView) row.findViewById(R.id.firstTxt);
t1.setText(""+ firstData[j]);
t2 = (TextView) row.findViewById(R.id.secondTxt);
t2.setText(""+ secondData[j]);
table.addView(row, new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
}
“row_details.xml”是一个包含两个文本视图(“firstTxt”,“secondTxt”)的布局。 我能够添加数据并显示在屏幕上。
当我将其旋转到横向模式时,问题就出现了,然后所有数据都会丢失。最初我认为这可能是由于方向问题(即由于重新加载活动而导致数据丢失)。
但是,当我第一次在横向模式下加载活动时,不会显示任何数据,现在旋转到纵向模式会显示数据。所以我认为这是由于横向模式下的膨胀造成的。
观察:- 纵向视图显示数据,横向视图不显示数据
我该如何解决这个问题?....提前致谢。
I had a strange problem. I am creating a table by inflating the table row like this
TableLayout table = (TableLayout) findViewById(R.id.tablelay);
LayoutInflater inflater = getLayoutInflater();
for (int j = 0; j < limit ; j++) {
TableRow row = (TableRow) inflater.inflate(R.layout.row_details, table, false);
t1 = (TextView) row.findViewById(R.id.firstTxt);
t1.setText(""+ firstData[j]);
t2 = (TextView) row.findViewById(R.id.secondTxt);
t2.setText(""+ secondData[j]);
table.addView(row, new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
}
The "row_details.xml" is a layout contains two textviews ("firstTxt" ,"secondTxt").
I am able to add data and is displayed on the screen.
The problems comes when i rotate it to landscape mode, then all the data is lost. Initially i thought this may due to orientation problem (ie data loss due to reloading the activity).
But first time when i load the activity in landscape mode then no data is displayed and now rotating to portrait mode shows the data. So i think this is due to inflating in landscape mode.
Observation :- portrait view shows data and landscape view shows no data
how do i solve this problem ?....thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从 android 文档中查看:
http://developer.android。 com/guide/topics/resources/runtime-changes.html
Try looking at this like from android documentation:
http://developer.android.com/guide/topics/resources/runtime-changes.html
添加menifest活动标签
configChange="orientation"
add in menifest activity tag
configChange="orientation"