Add Dynamic EditText with is this code but i got exception.
当我单击添加的edittext时,它又给出了另一行,但是我收到了非法状态Exception.This是我的代码。
LayoutInflater layoutInflater = getLayoutInflater();
final View callRowView = layoutInflater.inflate(R.layout.call_field,null);
callParent.addView(callRowView);
EditText editText = callRowView.findViewById(R.id.call_e_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
callParent.addView(callRowView);
return false;
}
});
请帮助我解决此问题。 谢谢
答案 0 :(得分:0)
我认为问题在于您不能在此方法内添加视图,此方法可能被调用多次,并且不必多次添加视图。
您应该放下该行并反转addView()
方法。检查下面。
LayoutInflater layoutInflater = getLayoutInflater();
final View callRowView = layoutInflater.inflate(R.layout.call_field,null);
EditText editText = callRowView.findViewById(R.id.call_e_text);
callParent.addView(callRowView);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}
});