Android: fastScrollEnabled сначала не работает
Хорошо, я работаю над приложением, которое имеет страницу со списком и поле для редактирования текста сверху. Когда вы вводите что-либо в поле редактирования текста, оно отфильтровывает, какие элементы отображаются в списке. У меня проблема с иконкой быстрой прокрутки, которая появляется на боковой панели ползунка.
Когда страница впервые загружается НЕТ, то, что я делаю, значок ползунка быстрой прокрутки не появится на экране. Затем я нажимаю в текстовом поле редактирования и набираю один символ, а затем стираю его, и теперь у меня появится значок ползунка быстрой прокрутки.
Первая загрузка не быстрая иконка прокрутки.
Окно редактирования текста, а затем удалите текст и появится значок быстрой прокрутки.
У меня есть андроид: fastScrollEnabled = & quot; true & quot; установить в моем списке просмотра. Кроме того, я установил это вручную в коде, выполнив lv1.setFastScrollEnabled (true);
Независимо от того, что я изменяю, я все равно получаю то же самое поведение, если только я не удалю его полностью из кода и xml, и тогда он перестанет работать на второй странице. Я пытался очистить свой проект, но все равно ничего не получилось. Я склоняюсь к тому, что это ошибка в Android, или я упускаю что-то очень простое.
Вот мой код
<code>public class SearchByFood extends ParentClass { private ListView lv1; private EditText ed; int textlength = 0; private ArrayList<String> arr_sort = new ArrayList<String>(); private ArrayList<String> foods = new ArrayList<String>(); private LayoutInflater mInflater; private ArrayList<Food> 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<String> to pass to the setAdapter Log.d("SearchByFood", "FoodName: " + f.getFood_Name()); foods.add(f.getFood_Name()); } ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(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 <= 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() > 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<String> adapter = new ArrayAdapter<String>(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<Integer> results = new ArrayList<Integer>(); for (int i = foodName.toLowerCase().indexOf(guess.toLowerCase()); i >= 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, "<b>"); count = count + 3; s1.insert(i + count + gLength, "</b>"); 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<?> parent, View view, int position, long id) { // Strip out the bold tags String clicked = (String) lv1.getItemAtPosition(position); clicked = clicked.replaceAll("<b>", ""); System.out.println("Clicked" + clicked); clicked = clicked.replaceAll("</b>", ""); // Find the Food ID match and pass the food id to the // fooddisplay page for (Food f : foodList) { if (null != clicked && 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>
Опять же, любая помощь в отношении того, почему мой значок быстрой прокрутки не отображается вначале, была бы очень признательна. Это маленькая вещь, но это действительно раздражает меня.