- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想添加一个 textview
和一个 checkbox
到 linearlayout
View :
for(int i = 0 ; i < helperitems.size() ; ++i){
final UserHelper u = helperitems.get(i);
runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayout linearLayout = new LinearLayout(ContentChatSendMessage.this);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setGravity(Gravity.RIGHT);
ViewGroup.LayoutParams txt_view_params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
CheckBox ch = new CheckBox(ContentChatSendMessage.this);
ch.setId(Integer.parseInt(u.getId()));
linearLayout.addView(ch);
TextView textView = new TextView(ContentChatSendMessage.this);
textView.setLayoutParams(txt_view_params);
textView.setText(u.getUsername1());
linearLayout.addView(ch);
arr_chs.add(ch);
lay_lin_parent.addView(linearLayout);
}
});
}
我的布局:
<LinearLayout
...
<LinearLayout
android:id="@+id/lay_lin_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginRight="4dp"
android:layout_marginLeft="4dp">
</LinearLayout>
...
</LinearLayout>
但是我得到这个错误:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
最佳答案
您的代码尝试将 CheckBox ch
添加到 linearLayout
两次。循环中的第二个 linearLayout.addView()
调用应该是:linearLayout.addView(textView);
。
关于android - 指定的子项已有父项。您必须先对 child 的 parent 调用 removeView(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34036021/
几个月前,我做了一个功能,我的应用程序正在等待用户文档并做出相应的响应。直到我对项目进行优化并将其更新到最新版本之前,它一直是一种魅力。 如果存在用户文档,则流将产生该文档并关闭该流。 如果云Fire
Stack Overflow 有几个 examples其中函数首先获得可升级锁,然后通过升级获得独占访问。我的理解是,如果不小心使用,这可能会导致死锁,因为两个线程可能都获得了可升级/共享锁,然后都尝
这个问题在这里已经有了答案: MVC 4 Code First ForeignKeyAttribute on property ... on type ... is not valid (1 个回答
以下是部分代码。我需要在 finally 子句中关闭资源。我需要先调用 closeEntry() 还是 close()?我收到一些错误消息。 Error closing the zipoutjava.
我想使用 RxJS-DOM 观察 mousewheel 事件,这样当第一个事件触发时,我转发它然后删除所有值,直到后续值之间的延迟超过先前指定的持续时间。 我想象的运算符可能看起来像: Rx.DOM.
版本似乎与安装的不同。 我在 npm install 上收到警告 我将二进制文件安装到我的家庭/开发目录中,但它不适用于 sudo。所以我安装了apt。 (注意:我并没有真正安装,我提取并将路径放在/
我正在尝试展示 GAN 网络在某些指定时期的结果。打印当前结果的功能以前与 TF 一起使用。我需要换成 pytorch。 def show_result(G_net, z_, num_epoch, s
我是一名优秀的程序员,十分优秀!