I am getting an object of RadioButton
by using findViewById()
and then setting an `onclicklistener' for it.The code goes like :
final EditText editTextView = (EditText)findViewById(2001);
RadioButton rb = (RadioButton) findViewById(R.id.radio3);
rb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.editTextGroupLayout);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
editTextView.setLayoutParams(params);
editTextView.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL| InputType.TYPE_NUMBER_FLAG_SIGNED);
editTextView.setId(2001);
linearLayout.addView(editTextView);
}
});
When i click Once on the radiobutton
it works fine.But when i click it twice,it generates
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
By clicking it twice why this exception occurs?
What i tried
I tried to remove the line final EditText editTextView = (EditText)findViewById(2001);
and add this line inside the onClick()
,EditText editTextView = (EditText)findViewById(2001);
.But by doing this it doesn't get executed even once.It shows exception
too.