There's an EditText in my activity and every time the user presses enter button on the keyboard, using OnEditorActionListener another EditText will be added to the LinearLayout.
The problem is after adding those views, the Button onClick doesn't work. Why is this happening and how to fix it?
button onClick:
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(NewExpenseActivity.this, "Saved", Toast.LENGTH_SHORT).show();
}
});
.
private TextView.OnEditorActionListener editorActionListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
createNewEditText();
}
return false;
}
};
.
public void createNewEditText() {
textInputLayout = new TextInputLayout(this);
textInputLayout.setPadding(padding_in_px_16, padding_in_px_8, padding_in_px_16, padding_in_px_8);
editText = new EditText(NewExpenseActivity.this);
editText.setId(id);
editText.setHint("Enter Name");
editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setOnEditorActionListener(editorActionListener);
editText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
textInputLayout.addView(editText);
ITEM_MAP.put("Key" + idNum, id);
idNum++;
linearEtList.addView(textInputLayout);
}