我正在尝试将复选框添加到布局中的视图中。问题是没有显示,但我知道正在添加,因为父视图的 getChildCount() 返回了一个新的更多项目..
我在处理程序中执行此操作,因为此方法在线程中调用。
protected void addDeviceToList(final String name, final ConnectSend cs) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(ConnectSend.this, "A: " + listOfPersons.getChildCount()+ " Vou adicionar um!", Toast.LENGTH_LONG).show();
CheckBox checkbox = new CheckBox(cs);
LinearLayout.LayoutParams fieldparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
checkbox.setTextAppearance(cs, android.R.attr.textAppearanceMedium);
checkbox.setText(name);
checkbox.setLayoutParams(fieldparams);
listOfPersons.addView(checkbox);
Toast.makeText(ConnectSend.this, "D: " + listOfPersons.getChildCount()+ " adicionei ", Toast.LENGTH_LONG).show();
}
});
}
非常感谢提前;)