android view父级隐藏,Android指定的子级已经有父级。必须先对子级的父级调用removeView()...
在我的應用中,我必須經常在兩種布局之間切換。錯誤在下面發布的布局中發生。
第一次調用布局時,沒有發生任何錯誤,一切都很好。然后,當我調用不同的布局(空白),然后再次調用我的布局時,出現以下錯誤:
> FATAL EXCEPTION: main
> java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我的布局代碼如下所示:
tv = new TextView(getApplicationContext()); // are initialized somewhere else
et = new EditText(getApplicationContext()); // in the code
private void ConsoleWindow(){
runOnUiThread(new Runnable(){
@Override
public void run(){
// MY LAYOUT:
setContentView(R.layout.activity_console);
// LINEAR LAYOUT
LinearLayout layout=new LinearLayout(getApplicationContext());
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);
// TEXTVIEW
layout.addView(tv); // <========== ERROR IN THIS LINE DURING 2ND RUN
// EDITTEXT
et.setHint("Enter Command");
layout.addView(et);
}
}
}
我知道之前曾有人問過這個問題,但對我來說沒有幫助。
總結
以上是生活随笔為你收集整理的android view父级隐藏,Android指定的子级已经有父级。必须先对子级的父级调用removeView()...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鸿蒙系统没有优势了吗,“鸿蒙系统”超震撼
- 下一篇: android和flask交互,java