English 中文(简体)
Android:快速发展 第一种工作能力
原标题:Android: fastScrollEnabled not working at first

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

First load no fast scroll icon.
no fast scroll icon
Edittext box and then erase text and fast scroll icon appears.
fast scroll appears

www.un.org/chinese/ga 除此以外,我还以人工方式将其编成法典,做了一半的工作。

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.

Here is my 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;
}
}


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.

最佳回答

<条码>清单.setFastScrollAlwaysVisible(true)

并尝试list.smoothScroll ToPosition(0);,以便icon在称为......时出现。

类似情况。

new Handler().postDelayed(new Runnable() {
  @Override
  public void run(){
    list.smoothScrollToPosition(0);
  }
}, 100);
问题回答

因此,我再次指出这一点,因为我的问题在本质上是不同的。 快速滚动似乎也在<条码>中发挥作用。 * E/CN.6/2009/1。 快速编程和<代码> 快速发展似乎不可行。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签