1

I would like to have Recyclerview with EditText views inside each row. I need to disable EditText for each row except the first one. I do it with

holder.edittext.isCursorVisible = false
holder.edittext.isClickable = false
holder.edittext.isFocusable = false
holder.edittext.isFocusableInTouchMode = false

However, I would like to have the ViewGroup of each row, for example, Linear Layout to be clickable in for all rows. Then I need to receive click events in EditText and pass it to ViewGroup even if the EditText is disabled. Is it possible to do so?

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Angelina
  • 1,473
  • 2
  • 16
  • 34
  • is this edittext your direct child to parent view? if yes then your code should work. if no then you will need to add this properties to intermediate parent. – karan Oct 22 '18 at 13:01
  • Yes, it is a direct child. Nilesh's answer worked. I marked it as the accepted answer. – Angelina Oct 22 '18 at 13:06

1 Answers1

2

Disable EditText

You can use holder.edittext.isFocusable = false to disable your EditText

Then I need to receive click events in EditText and pass it to ViewGroup even if the EditText is disabled. Is it possible to do so?

You can set ClickListener to your EditText and pass click event to your ViewGroup using performClick()

  • performClick ()

    Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.

SAMPLE CODE

public class MainActivity extends AppCompatActivity {


    EditText myEditText;
    LinearLayout rootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myEditText = findViewById(R.id.myEditText);
        rootView = findViewById(R.id.rootView);

        myEditText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rootView.performClick();

            }
        });

        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "Prem", Toast.LENGTH_SHORT).show();
            }
        });
    }

}

EDIT

as per your below comment how can I disable my EditText changing colour on touch/click even when I have it focusable = false?

follow this answer when selected add border shape for textView and editText ,

Community
  • 1
  • 1
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • Thanks! @Nilesh, how can I disable my EditText changing colour on touch/click even when I have it focusable = false? – Angelina Oct 22 '18 at 13:05
  • @Angelina follow this answer it will help you https://stackoverflow.com/questions/52353887/when-selected-add-border-shape-for-textview-and-edittext/52922364#52922364 – AskNilesh Oct 22 '18 at 13:06