Android: fastScrollEnabled na początku nie działa

OK, pracuję nad aplikacją, która ma stronę z listview i polem edittext na górze. Podczas wpisywania rzeczy w polu edittext będzie filtrować elementy wyświetlane w widoku listy. Problem mam z ikoną szybkiego przewijania, która pojawia się z boku suwaka.
Gdy strona ładuje się po raz pierwszy NIE MA, co robię, ikona szybkiego suwaka nie pojawi się na ekranie. Następnie klikam w polu edycji i wpisuję jeden znak, a następnie kasuję go, a teraz pojawi się ikona suwaka szybkiego przewijania.

Pierwsze załadowanie bez ikony szybkiego przewijania.

Zostanie wyświetlone pole Edittext, a następnie skasuj tekst i ikonę szybkiego przewijania.


Mam android: fastScrollEnabled = "true" ustawiony w moim widoku listy. Plus ustawiłem go ręcznie w kodzie, wykonując lv1.setFastScrollEnabled (true);

Bez względu na to, że się zmienię, nadal zachowuję to samo zachowanie, chyba że usunę je kompletnie z kodu i xml, a następnie przestanie działać na drugiej stronie. Próbowałem oczyścić mój projekt i nadal nie jestem dobry. Skłaniam się ku temu, że jest to błąd w Androidzie lub brakuje mi czegoś niezwykle prostego.

Oto mój kod.

<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>


Ponownie, wszelka pomoc, dlaczego moja ikona szybkiego przewijania nie pojawia się na początku, byłaby bardzo mile widziana. To mała rzecz, ale naprawdę mnie denerwuje.

questionAnswers(2)

yourAnswerToTheQuestion