Angular, PWA, C#, ASP.NET, Node.js, Docker, React, IONIC, IoT & more …

Android: TabHost is stealing focus from a EditText


I am recently working on Android app development and had an issue with TabHost and EditText inside that TabHost. 

somehow, when I was trying to insert a value in that EditText, focus was set automatically on tab and was not able to type anything. 

Tried hard to google and came to know that its a bug and Good team is working on it as of today. But there is a workaround for this problem as below – 

 

txtDescription = (EditText) V.findViewById(R.id.txtAttactmentDescription);
txtDescription.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
txtDescription.requestFocusFromTouch();
return false;
}
});

10 responses to “Android: TabHost is stealing focus from a EditText”

  1. Youssef Bsf Avatar
    Youssef Bsf

    You Saaaaaaaaaaaaved My Liiiiiiiiiiife !!!!!!!!!

    Like

  2. IS Avatar
    IS

    My problem is solved. Thank you

    Like

    1. Bhavin Patel Avatar
      Bhavin Patel

      Glad that it worked for you… Happy coding 🙂

      Like

  3. Vijeth AG Avatar
    Vijeth AG

    That worked like a charm! kudos!

    Like

    1. Bhavin Patel Avatar
      Bhavin Patel

      Thanks … 🙂

      Like

  4. Mart Avatar
    Mart

    Great! Thank you so much!

    Like

  5. Andy Avatar
    Andy

    You saved me! I was about to give up after spending almost a whole day on this issue!

    Like

  6. Hoang Avatar
    Hoang

    Or you can remove OnTouchModeChangeListener of the Tabhost:
    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {

    @Override
    public void onViewDetachedFromWindow(View v) {}

    @Override
    public void onViewAttachedToWindow(View v) {
    mTabHost.getViewTreeObserver().removeOnTouchModeChangeListener(mTabHost);
    }
    });

    Source: https://code.google.com/p/android/issues/detail?id=2516

    Like

  7. Alessandro Mattiuzzi Avatar
    Alessandro Mattiuzzi

    Not solved for me. This is really a bad bug.

    Like

    1. Bhavin Patel Avatar
      Bhavin Patel

      Samsung changed snote format in newer versions so unfortunately no sol. Yet.

      Like

Leave a comment