Note that there are some explanatory texts on larger screens.

plurals
  1. POsetFastScrollEnabled don't work perfectly
    primarykey
    data
    text
    <p>I am working on an App that has a page with a listview and a edittext box at top. As you type things into the edittext box it will filter what items are shown in the listview. The problem I am having is with the fast scroll icon that appears on the side of the slider. The scroller go out the view when i type the letter "b for example.</p> <p><img src="https://i.stack.imgur.com/gAqKN.png" alt="enter image description here"></p> <p>I have added this lines (to refresh my list scroller) and it didn't work.</p> <pre><code>_filterText = (EditText) findViewById(R.id.search_box); _filterText.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) { _listView.setFastScrollEnabled(false); _listView.setFastScrollEnabled(true); } </code></pre> <p>i have also se this subject and follow it, and i guess it wasn't the same problem. <a href="https://stackoverflow.com/questions/10255624/android-fastscrollenabled-not-working-at-first">Android: fastScrollEnabled not working at first</a></p> <p>Ok, here is all my class:</p> <pre><code>public class StationsFragment extends GoogleAnalyticsFragment implements Observer{ private Boolean mDebug = true; private ListView _listView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView( inflater, container, savedInstanceState ); activity = (FragmentsActivity) getActivity(); mStationsViewContainer = inflater.inflate(R.layout.stations_activity, null); _listView = (ListView) mStationsViewContainer.findViewById( R.id.stations_listView ); activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); _stationsAdapter = new StationsAdapter(); _listView.setAdapter(_stationsAdapter); _listView.setVerticalScrollBarEnabled(false); _listView.setFastScrollEnabled(true); _listView.setScrollingCacheEnabled(true); registerForContextMenu(_listView); _listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { } }); _stationsList.addObserver(this); _filterText = (EditText) mStationsViewContainer.findViewById( R.id.search_box ); TextWatcher filterTextWatcher = new TextWatcher() { public void afterTextChanged(Editable s) { _listView.setFastScrollEnabled(false); _listView.setFastScrollEnabled(true); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { _filterMode = _filterText.getText().length() &gt; 0; _stationsAdapter.getFilter().filter(s); } }; _filterText.addTextChangedListener(filterTextWatcher); _stationsAdapter.getFilter().filter(""); } return mStationsViewContainer; } class StationsAdapter extends BaseAdapter implements SectionIndexer, Filterable { HashMap&lt;String, Integer&gt; _alphaIndexer; public ArrayList&lt;Station&gt; _filtered = new ArrayList&lt;Station&gt;(); String[] _sections; MyFilter _filter; public StationsAdapter() { super(); _filter = new MyFilter(); } public void updateIndex() { _alphaIndexer = new HashMap&lt;String, Integer&gt;(); for (int x = 0; x &lt; _filtered.size(); x++) { Station s = (Station) _filtered.get(x); // get the first letter of the store String ch = s.getTitle().substring(0, 1); // convert to uppercase otherwise lowercase a -z will be sorted // after upper A-Z ch = ch.toUpperCase(); if (!_alphaIndexer.containsKey(ch)) { if (_filterMode) { _alphaIndexer.put(ch, x); } else { _alphaIndexer.put(ch, x + _favouriteManager.getFavourites().length); } } } Set&lt;String&gt; sectionLetters = _alphaIndexer.keySet(); ArrayList&lt;String&gt; sectionList = new ArrayList&lt;String&gt;(sectionLetters); Collections.sort(sectionList); if (!_filterMode &amp;&amp; _favouriteManager.getFavourites().length &gt; 0) { sectionList.add(0, "\u2605"); } _sections = new String[sectionList.size()]; sectionList.toArray(_sections); if (!_filterMode &amp;&amp; _favouriteManager.getFavourites().length &gt; 0) { _alphaIndexer.put("\u2605", 0); } } public int getCount() { if (_filterMode) { if (mDebug) Log.i("StationFragment","filter size ="+_filtered.size()); return _filtered.size(); } else { return _filtered.size() + _favouriteManager.getFavourites().length; } } public Object getItem(int position) { if (_filterMode) { return _filtered.get(position); } else { if (position &lt; _favouriteManager.getFavourites().length) { return _favouriteManager.getFavourites()[position]; } else { return _filtered.get(position - _favouriteManager.getFavourites().length); } } } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { if (mDebug) Log.i("ks3","getView called, position is " + position); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) activity.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.stations_cell_custom, null); } if (!_filterMode) { if (position &lt; _favouriteManager.getFavourites().length) { Favourite favourite = _favouriteManager.getFavourites()[position]; Station station = _stationsList.findStationById(favourite.getFavouriteId()); TextView details = ((TextView) convertView.findViewById(R.id.details)); if (_pushedFromRoutes || _pushedFromWidgetConfiguration) { details.setVisibility(View.GONE); } else { details.setVisibility(View.VISIBLE); } TextView name = ((TextView) convertView.findViewById(R.id.name)); if (station != null) { name.setText(station.getName()); //name.setTextColor(getResources().getColor(R.color.stations_list_favourite_text_color)); } else { name.setText(""); } details.setText(favourite.getUserSettings().formattedDateTime()); TextView header = ((TextView) convertView.findViewById(R.id.header_textview)); View headerBar = ((View) convertView.findViewById(R.id.header_bar)); if (position == 0) { header.setVisibility(View.VISIBLE); headerBar.setVisibility(View.VISIBLE); header.setText(getString(R.string.star_favourites)); } else { header.setVisibility(View.GONE); headerBar.setVisibility(View.GONE); header.setText(null); } } else { Station station = _filtered.get(position - _favouriteManager.getFavourites().length); TextView name = ((TextView) convertView.findViewById(R.id.name)); name.setText(station.getName()); name.setTextColor(getResources().getColor(R.color.stations_list_text_color)); ((TextView) convertView.findViewById(R.id.details)).setVisibility(View.GONE); TextView header = ((TextView) convertView.findViewById(R.id.header_textview)); View headerBar = ((View) convertView.findViewById(R.id.header_bar)); String firstLetter = station.getTitle().substring(0, 1); /*if (position == _alphaIndexer.get(firstLetter)) { TextView header = (TextView) activity.findViewById(R.id.header_textview); header.setText(firstLetter); }*/ if (position == _alphaIndexer.get(firstLetter)) { header.setVisibility(View.VISIBLE); headerBar.setVisibility(View.VISIBLE); header.setText(firstLetter); } else { header.setVisibility(View.GONE); headerBar.setVisibility(View.GONE); header.setText(null); } } } else { Station station = _filtered.get(position); TextView name = ((TextView) convertView.findViewById(R.id.name)); name.setText(station.getName()); name.setTextColor(getResources().getColor(R.color.stations_list_text_color)); ((TextView) convertView.findViewById(R.id.details)).setVisibility(View.GONE); TextView header = ((TextView) convertView.findViewById(R.id.header_textview)); View headerBar = ((View) convertView.findViewById(R.id.header_bar)); String firstLetter = station.getTitle().substring(0, 1); if (position == _alphaIndexer.get(firstLetter)) { header.setVisibility(View.VISIBLE); headerBar.setVisibility(View.VISIBLE); header.setText(firstLetter); } else { header.setVisibility(View.GONE); headerBar.setVisibility(View.GONE); header.setText(null); } } return convertView; } public int getPositionForSection(int section) { return _alphaIndexer.get(_sections[section]); } public int getSectionForPosition(int position) { return 0; } public Object[] getSections() { return _sections; } @Override public Filter getFilter() { return _filter; } class MyFilter extends Filter { @Override public CharSequence convertResultToString(Object resultValue) { if (resultValue != null) { Station station = (Station) resultValue; if (station != null) { return station.getTitle(); } } return null; } @Override protected FilterResults performFiltering(CharSequence constraint) { String pattern = constraint.toString().toLowerCase(); FilterResults result = new FilterResults(); ArrayList&lt;Station&gt; filt = new ArrayList&lt;Station&gt;(); if (_pushedFromRoutes || _pushedFromWidgetConfiguration) { synchronized (_stationsList.stations()) { for (int i = 0, l = _stationsList.stations().length; i &lt; l; i++) { Station s = _stationsList.stations()[i]; if (pattern == null || pattern.length() == 0 || s.match(pattern)) filt.add(s); } result.count = filt.size(); result.values = filt; } } else { synchronized (_stationsList.belgianStations()) { for (int i = 0, l = _stationsList.belgianStations().length; i &lt; l; i++) { Station s = _stationsList.belgianStations()[i]; if (pattern == null || pattern.length() == 0 || s.match(pattern)) filt.add(s); } result.count = filt.size(); result.values = filt; } } return result; } @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { _filtered = (ArrayList&lt;Station&gt;) results.values; updateIndex(); _listView.setFastScrollEnabled(false); notifyDataSetChanged(); _listView.setFastScrollEnabled(true); if (mDebug) Log.i("StationFragment","list count ="+_listView.getCount()); if (_filterMode &amp;&amp; _filtered.size() == 0) { _listView.setVisibility(View.GONE); _noResultsTextView.setVisibility(View.VISIBLE); } else { _listView.setVisibility(View.VISIBLE); _noResultsTextView.setVisibility(View.GONE); } } } } } </code></pre> <p>You see that i have to generate a complex list, i think that the problem may come from this, maybe scroller can get the max and the min? i really don't get it?</p> <p>I tried my code in an activity (i thunked that maybe problem comes from fragment) and when i test it , it still don't work in my tablet Samsung Galaxy. i tried it in a Nexus S and it worked. The problem i must use this code in a fragment and it must work in the tablet especially GalaxyTab.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload