我正在尝试将复选框添加到我在布局上的视图中。问题是没有显示,但我知道正在添加因为父视图中的getChildCount()返回一个新的更多项目..
我在处理程序中执行此操作,因为此方法在Thread内部调用。
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();
}
});
}
提前多多谢谢;)
答案 0 :(得分:1)
尝试使用checkbox.setVisibility(View.VISIBLE)