I have created one custom view that extends constraintsalyout. Inside that view, I added EditText and Textview. When I try to add this custom view inside recycler view, Its not showing keyboard when I touch on that edittext.
Its perfectly working when added outside of recycler view
public class SVEditText extends ConstraintLayout {
private Context context;
private EditText editText;
private TextView textView;
public SVEditText(final Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.sv_edittext, this);
editText = view.findViewById(R.id.editText);
textView = view.findViewById(R.id.textView);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SVEditText);
editText.setText(typedArray.getString(R.styleable.SVEditText_text));
editText.setHint(typedArray.getString(R.styleable.SVEditText_hint));
editText.setLines(typedArray.getInteger(R.styleable.SVEditText_android_lines, 1));
editText.setInputType(typedArray.getInteger(R.styleable.SVEditText_android_inputType, 0));
textView.setText(typedArray.getString(R.styleable.SVEditText_title));
setDrawablesToEditText(typedArray);
typedArray.recycle();
}
private void setDrawablesToEditText(TypedArray typedArray){
if (typedArray.getInteger(R.styleable.SVEditText_android_lines, 1) != 1){
Drawable innerDrawableLeft = typedArray.getDrawable(R.styleable.SVEditText_iconLeft);
Drawable innerDrawableRight = typedArray.getDrawable(R.styleable.SVEditText_iconRight);
GravityCompoundDrawable iconLeft = null, iconRight = null;
if (innerDrawableLeft != null) {
iconLeft = new GravityCompoundDrawable(innerDrawableLeft);
innerDrawableLeft.setBounds(0, 30, innerDrawableLeft.getIntrinsicWidth(), innerDrawableLeft.getIntrinsicHeight()+30);
iconLeft.setBounds(0, 0, innerDrawableLeft.getIntrinsicWidth(), innerDrawableLeft.getIntrinsicHeight());
iconLeft.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_IN));
}
if (innerDrawableRight != null) {
iconRight = new GravityCompoundDrawable(innerDrawableRight);
innerDrawableRight.setBounds(0, 30, innerDrawableRight.getIntrinsicWidth(), innerDrawableRight.getIntrinsicHeight()+30);
iconRight.setBounds(0, 0, innerDrawableRight.getIntrinsicWidth(), innerDrawableRight.getIntrinsicHeight());
iconRight.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_IN));
}
editText.setCompoundDrawablesWithIntrinsicBounds(iconLeft,
null, iconRight, null);
editText.setBackgroundResource(R.drawable.bg_edit_multiline);
return;
}
editText.setCompoundDrawablesWithIntrinsicBounds(typedArray.getDrawable(R.styleable.SVEditText_iconLeft),
null, typedArray.getDrawable(R.styleable.SVEditText_iconRight), null);
}
public void setText(String value){
editText.setText(value);
}
public void setHint(String hint){
editText.setHint(hint);
}
public void setTitle(String title){
textView.setText(title);
}
public void setCompoundDrawablesWithIntrinsicBounds( @DrawableRes int left, @DrawableRes int top, @DrawableRes int right, @DrawableRes int bottom){
editText.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
}
public void setText(Spannable spannable) {
editText.setText(spannable);
}
}
Finally I found the mistake I made. I missed this line in xml.
android:inputType="phone"
So it is taken as 0 default from my custom view code. I updated that default value as 1, now it is working without adding inputtype in xml.