【发布时间】:2013-02-14 17:14:11
【问题描述】:
我的情况如下: 在我的布局 xml 中,我有一个通用的 LinearLayout 作为主容器,我想基于一个分页系统填充内容,所有内容都包含在单个活动中。
我的Java代码如下:
private void goToPage(int pageNum){
LinearLayout layout = (LinearLayout)this.findViewById(R.id.layoutRadioGroups);
//Clear Views
layout.removeAllViews();
//Figure out array positions based on page number
if (pageNum < this.PAGE_NUM)
this.LAST_QUESTION_START -= this.NUM_PER_PAGE[pageNum];
else{
if (pageNum > 0)
this.LAST_QUESTION_START += this.NUM_PER_PAGE[pageNum - 1];
else
this.LAST_QUESTION_START = 0;
}
this.PAGE_NUM = pageNum;
//Grab my array values, create a TextView, and add it to the layout
for (int i=this.LAST_QUESTION_START; i < this.LAST_QUESTION_START + this.NUM_PER_PAGE[pageNum]; i++){
TextView tv = new TextView(layout.getContext());
tv.setText(this.QUESTIONS[i]);
tv.setId(i);
layout.addView(tv);
}
}
因此,它会清除所有视图(仅是 TextView 的),找出正确的数组值来制定 TextView 对象,然后将它们添加到我的布局中。
现在第 0 页显示正确,当我单击下一步按钮时,第 1 页也正确显示。但是当我转到第2页时,第1页的内容还在,第2页的内容覆盖在上面。
我是 Android 开发的新手,所以我不确定我没有刷新某些内容或使某些内容无效,但我很困惑。大家有什么想法吗?
谢谢!
【问题讨论】:
标签: android android-activity overlap viewgroup