0

I have an EditText that is focused and a Button that is not focused.

When I click the Button, the EditText loses focus.

When I long-click the Button, the EditText does not lose focus.

Whats the source of this behaviour? I want to achieve the long-click behaviour within a default click, is this possible?

Csharpest
  • 1,258
  • 14
  • 32

1 Answers1

0

Long click behavior is for by default for ClipBoard actions . If you want to override it with Single click . You can do this as follows.

editText=(EditText)findViewById(R.id.txt);
    editText.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // Do your stuff
            return true;
        }
    });
    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.performLongClick();

        }
    });

If you are doing it to just get rid of Focusing problem then its not the way.

ADM
  • 20,406
  • 11
  • 52
  • 83
  • If you are doing it to just get rid of Focusing problem then you should not do this . Add your Xml . – ADM Jan 22 '18 at 12:17
  • I actually want it the other way round, my click should perform a longclick. but i tried it like you just showed it (perform longlick in onclicklistener) and it would not fix the focus issue. – Csharpest Jan 22 '18 at 12:18
  • See the updated answer . What exactly you want to do on long click because if you do so it will omit the `ClipBoard` actions. – ADM Jan 22 '18 at 12:22
  • I dont care about the clipboard actions. Im actually using xamarin.forms + xamarin.android. I have an edittext that has its focus bool property bound to the visibility of another layout (grid with multiple buttons). When i hit one of the buttons, the focus is lost on the edittext. I dont want the focus to be lost. Requesting the focus on button click also doesnt work, because there will be a small duration between the lost focus of the edittext and the newly assign focus to it. I just found out that the longclick doesnt make the edittext lose the focus. – Csharpest Jan 22 '18 at 12:25
  • It is basically a layout of 4 columns and 1-10 rows (dynamically defined at runtime) and buttons in each of the columns/rows. Could I recreate this layout in (xamarin.)android (it is made in xamarin.forms right now) and add it to the EditTexts view? It is important, that this layout is toggled via the focus of the edittext and it should not take space but rather overlap any views that are below the edittext – Csharpest Jan 22 '18 at 12:28