Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide soft input when listview scroll

The xml is as follow.

enter image description here

I want to implement the function like this: when I click the edittext, the soft input show. when I scroll(not scroll to OnScrollListener.SCROLL_STATE_IDLE state) the listview the soft input hide.

I use the android:windowSoftInputMode="adjustResize" .

like image 232
Cruisehu Avatar asked Jan 05 '15 06:01

Cruisehu


People also ask

Will bottomnavigationview show and hide on scrolling?

When a BottomNavigationView will show and hide on scrolling it will look much more professional and practical. You have also seen in LinkedIn, that how it’s BottomNavigationView shows and hide on scrolling. Do you also not want to implement it in BottomNavigationView of your own app.

How to scroll to random items in a listview?

In case the heights of the items are different and not set, move on to another method in this article. This example app contains a ListView with 100 items and a floating button. When the user presses the floating button, the view will scroll to a random item (you can replace it with a constant number if you want to).

How do I hide the soft keyboard in Android Studio?

Define an interface to hide the soft keyboard. In a native Android project, create a class to hide the keyboard and register the dependency for the same. Hide the soft keyboard using HideSoftInputFromWindow method , and clear the focus using ClearFocus method.

How to hide the keyboard in Xamarin scrollstatechanged?

Trigger the ScrollStateChanged method to hide the keyboard. In the event call back, call the HideKeyBoard method using DependencyService when the ScrollState is not Idle. The ultimate Xamarin UI toolkit to boost your development speed.


2 Answers

Detect your scroll using this link, it implements onScrollListener, which you will set to your ListView and in its onScrollStateChanged() you will put this code in your -

setOnScrollListener(new OnScrollListener(){
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
      // TODO Auto-generated method stub
    }
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (scrollState !=0){
           InputMethodManager inputMethodManager = (InputMethodManager) 
           getSystemService(Activity.INPUT_METHOD_SERVICE);     
           inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(‌​), 0);
        }
    }
});
like image 84
Darpan Avatar answered Sep 18 '22 04:09

Darpan


InputMethodManager inputMethodManager = (InputMethodManager) 
           getSystemService(Activity.INPUT_METHOD_SERVICE);     
           inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(‌​), 0);

gives a bug in AS... Use this instead inside onScrollStateChange

InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    in.hideSoftInputFromWindow(absListView.getApplicationWindowToken(), 0);
like image 25
Farmaker Avatar answered Sep 21 '22 04:09

Farmaker