EditText as part of HeaderView loses focus on input

This is a problem that I only have to face for Android 4.0 devices.

I currently have a listView and a custom title that I am adding onCreate () to ListActivity.

I am using editText as a custom searchBar in the application.

Below is a code snippet that hopefully explains my implementation.

  private ListView lst_Reports = null;

 @Override
 public void onCreate (Bundle savedInstanceState) {
     super.onCreate (savedInstanceState);

     setContentView (R.layout.showreportlist);

     lst_Reports = (ListView) findViewById (R.id.VuoShowReportsActivity_Lst_Reports);

     / *
      * Initialize UI
      * /

     LinearLayout headerView = (LinearLayout) View.inflate (this, R.layout.report_list_header, null);
     EditText reportSearchBar = (EditText) headerView.findViewById (R.id.reportSearchBar);
     lst_Reports.addHeaderView (headerView);

     reportSearchBar.addTextChangedListener (new TextWatcher () {

         public void afterTextChanged (Editable s) {

         }

         public void beforeTextChanged (CharSequence s, int start, int count, int after) {

         }

         public void onTextChanged (CharSequence s, int start, int before, int count) {

             // do a search as and when the user inputs text

             if (s! = null && s.length ()> 0) {

                 String query = s.toString ();
                 List queriedReports = getReportsBasedOnQueryString (query);

              // populate the listView with the queriedReports

             }

         }

     });

 }

 protected List getReportsBasedOnQueryString (String query) {
     // TODO Auto-generated method stub
     return null;
 }

When this code runs on an Android 2.3.5 device, I can normally enter it in editText. However, when the same piece of code is deployed on a Galaxy S3 that has an ice cream sandwich, I can only enter one character at a time in editText, as it continues to lose focus after each key entry.

I have already tried the following suggested solutions to similar problems. None of them solved the problem.

  • for activity in AndroidManifest:

    • Android: windowSoftInputMode = "stateHidden"
    • Android: windowSoftInputMode = "adjustPan"
  • in the xml layout of the activity:

    • Android: descendantFocusability = "beforeDescendants"

I appreciate any help / feedback on this, and I also want to know if anyone else has reported the same issue.

Thanks Rajat

+4
source share
1 answer
 public void onTextChanged(CharSequence s, int start, int before, int count) { // do a search as and when the user inputs text if (s != null && s.length() > 0) { String query = s.toString(); List queriedReports = getReportsBasedOnQueryString(query); // populate the listView with the queriedReports } // add below line in your code reportSearchBar.requestFocus(); } 
0
source

Source: https://habr.com/ru/post/1484643/


All Articles