Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: fastScrollEnabled not working at first
    primarykey
    data
    text
    <p>OK, 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.<br> When the page first loads NO MATTER what I do the fast scroll slider icon will not appear on the screen. Then I click in the edit text box and type one character and then erase it and now my fast scroll slider icon will appear.<br> <br> First load no fast scroll icon.<br> <img src="https://i.stack.imgur.com/rnfdi.png" alt="no fast scroll icon"> <br> Edittext box and then erase text and fast scroll icon appears.<br> <img src="https://i.stack.imgur.com/2DLOd.png" alt="fast scroll appears"></p> <p><br> I have the android:fastScrollEnabled="true" set in my listview. Plus I have set it manually in the code by doing lv1.setFastScrollEnabled(true);</p> <p>No matter I change I still get the same behavior, unless I remove it complete from the code and xml and then it will stop working on the second page. I have tried cleaning my project and still no good. I am leaning towards it being a bug in android or I am missing something extremely simple.<br> <br> Here is my code. </p> <pre><code>public class SearchByFood extends ParentClass { private ListView lv1; private EditText ed; int textlength = 0; private ArrayList&lt;String&gt; arr_sort = new ArrayList&lt;String&gt;(); private ArrayList&lt;String&gt; foods = new ArrayList&lt;String&gt;(); private LayoutInflater mInflater; private ArrayList&lt;Food&gt; foodList; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_by_food); setTextTitle("Search by Food"); lv1 = (ListView) findViewById(R.id.ListView01); ed = (EditText) findViewById(R.id.EditText01); mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); DataLayerFunctions d = new DataLayerFunctions(getApplicationContext()); foodList = d.selectFoodsWithSubstitutes(); for (Food f : foodList) { // this is to build a ArrayList&lt;String&gt; to pass to the setAdapter Log.d("SearchByFood", "FoodName: " + f.getFood_Name()); foods.add(f.getFood_Name()); } ArrayAdapter&lt;String&gt; firstAdapter = new ArrayAdapter&lt;String&gt;(SearchByFood.this, R.layout.search_food_listview, foods); lv1.setAdapter(firstAdapter); lv1.setFastScrollEnabled(true); ed.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) { textlength = ed.getText().length(); arr_sort.clear(); for (String f : foods) { if (textlength &lt;= f.length()) { if (f.toString().toLowerCase().contains((CharSequence) ed.getText().toString().toLowerCase())) { Log.d("STRING", "STRING: " + f.toString() + " contains " + ed.getText()); if (ed.getText().length() &gt; 0) { String newString = boldMyString(f, ed.getText().toString()); arr_sort.add(newString); } else { arr_sort.add(f); } } } } // if empty add a no foods found if (arr_sort.isEmpty()) { arr_sort.add("No Foods Found"); } // Load array // lv1.setAdapter(new ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(SearchByFood.this, R.layout.search_food_listview, arr_sort) { @Override public View getView(int position, View convertView, ViewGroup parent) { View row; if (null == convertView) { row = mInflater.inflate(R.layout.search_food_listview, null); } else { row = convertView; } TextView tv = (TextView) row.findViewById(android.R.id.text1); tv.setText(Html.fromHtml(getItem(position))); // tv.setText(getItem(position)); return row; } }; lv1.setAdapter(adapter); } private String boldMyString(String foodName, String guess) { int gLength = guess.length(); ArrayList&lt;Integer&gt; results = new ArrayList&lt;Integer&gt;(); for (int i = foodName.toLowerCase().indexOf(guess.toLowerCase()); i &gt;= 0; i = foodName.toLowerCase() .indexOf(guess.toLowerCase(), i + 1)) { System.out.println("TEST:" + i); results.add(i); } // Count value is for words that have 2 or more values of guess // in them. int count = 0; for (int i : results) { StringBuffer s1 = new StringBuffer(foodName); s1.insert(i + count, "&lt;b&gt;"); count = count + 3; s1.insert(i + count + gLength, "&lt;/b&gt;"); count = count + 4; foodName = s1.toString(); System.out.println("FOOD NAME:" + i + ":" + foodName); } return foodName; } }); // This is what actually does stuff when you click on a listview item. lv1.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // Strip out the bold tags String clicked = (String) lv1.getItemAtPosition(position); clicked = clicked.replaceAll("&lt;b&gt;", ""); System.out.println("Clicked" + clicked); clicked = clicked.replaceAll("&lt;/b&gt;", ""); // Find the Food ID match and pass the food id to the // fooddisplay page for (Food f : foodList) { if (null != clicked &amp;&amp; clicked.equals(f.getFood_Name())) { Intent intent = new Intent(SearchByFood.this, SubstituteDisplay.class); intent.putExtra("FoodID", f.getFood_ID()); startActivity(intent); } } } }); } @Override public void onBackPressed() { final Intent intent = new Intent(this, MasterTemplateActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); this.startActivity(intent); return; } } </code></pre> <p><br> Again, any help as to why my fast scroll icon doesn't show up at first would be much appreciated. It is a small thing but it is really annoying me. </p>
    singulars
    1. This table or related slice is empty.
    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