cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(android.widget.CompoundButton buttonView,boolean isChecked) {
// TODO Auto-generated method stub
String str="";
if(cb.isChecked()) {
/*//int tag=(Integer) cb.getTag();
final EditText et=new EditText(NewOrder.this);
et.setTextColor(Color.BLACK);
et.setTextSize(16);
et.setPadding(10, 5, 10, 5);
//et.setBackgroundDrawable(NewOrder.this.getResources().getDrawable(R.drawable.edittext_border));
tr.addView(et);
// table.addView(tr);
//Long tag = (Long) buttonView.getTag();
*/
str=str+cb.getText();
adapter3.add(str);
//String t= tag.toString();
Toast.makeText(NewOrder.this, str, Toast.LENGTH_LONG).show();
} else //(!(cb.isChecked())) {
str=str+cb.getText();
adapter3.remove(str);
// Toast.makeText(NewOrder.this, str, Toast.LENGTH_LONG).show();
}
}
});
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
} catch (Exception e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
答案 0 :(得分:0)
不是试图通过创建一个在运行时将EditText添加到视图,而是可以尝试从开头添加它,然后切换其可见性,如:
if(cb.isChecked())
{
// ....
et.setVisibility(View.VISIBLE);
// ....
}
else //(!(cb.isChecked()))
{
// ....
et.setVisibility(View.GONE);
// ....
}
实施整个项目以使用或忽略EditText可见性。