Sanyasirao Mopada Sanyasirao Mopada - 16 days ago 5
Android Question

How to remove focus from edittext after setting sometext intially in programmatically?

I have an edit-text for date, and I am setting today's date as default date programmatically by, and I am opening a date-picker when focus changes, So here date-picker is opening when user opens the fragment, but I want to close it for the first time, How to achieve that?. Help me

date.setText(dateFormatter.format(new Date()));

Answer

I achieved it by removing focus when ondrawerClosed being called by navigation drawer

//In activity or fragment where we have navigation drawer
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            interfaceListener.removeFocus();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

//In fragment

public void removeFocus(){
    editext.clearFocus();
    anotherLinearLayout.requestFocus();
}