滚动AlphabetIndexer时快速滚动的拇指消失

我有一个ListViewfastScrollAlwaysVisiblefastScrollEnabled都设置为true 。 在我的Adapter和一个AlphabetIndexer实现SectionIndexer后,我的fast scroll thumb将消失,而我滚动,然后再次出现,一旦我到达列表的顶部或底部。 我对于为什么会发生这些事情一无所知。 我以前没有经历过。

AlphabetIndexer而言,下面的所有内容都是有效的。 我的问题是为什么当我滚动时,快速滚动的拇指消失,我怎么能阻止它消失?

fast scroll是否始终可见并不重要。 每当fast scroll可见, fast scroll thumb不在那里,它只是消失了,这就是我的问题。 此外,当我删除AlphabetIndexer fast scroll thumb工作,就像我打算这样做。 一切都能在一个Activity成功运行,但是当我在一个Fragment加载我的ListView ,事情就像我解释的那样。

这是我的ListView Adapter

 private class AlbumsAdapter extends SimpleCursorAdapter implements SectionIndexer { private AlphabetIndexer mIndexer; // I have to override this because I'm using a `LoaderManager` @Override public Cursor swapCursor(Cursor cursor) { if (cursor != null) { mIndexer = new MusicAlphabetIndexer(cursor, mAlbumIdx, getResources().getString(R.string.fast_scroll_alphabet)); } return super.swapCursor(cursor); } @Override public Object[] getSections() { return mIndexer.getSections(); } @Override public int getPositionForSection(int section) { return mIndexer.getPositionForSection(section); } @Override public int getSectionForPosition(int position) { return 0; } } 

MusicAlphabetIndexer帮助正确sorting音乐:

 class MusicAlphabetIndexer extends AlphabetIndexer { public MusicAlphabetIndexer(Cursor cursor, int sortedColumnIndex, CharSequence alphabet) { super(cursor, sortedColumnIndex, alphabet); } @Override protected int compare(String word, String letter) { String wordKey = MediaStore.Audio.keyFor(word); String letterKey = MediaStore.Audio.keyFor(letter); if (wordKey.startsWith(letter)) { return 0; } else { return wordKey.compareTo(letterKey); } } } 

Related of "滚动AlphabetIndexer时快速滚动的拇指消失"

我有类似的问题与快速滚动的拇指图标。 我正在调查Android的源代码,发现一个提交引入了这个问题和其他(ArrayIndexOutOfBoundsException)。 我甚至没有这个提交,甚至build立了Android系统,它的工作。

我在六月份提交了这个问题: https : //code.google.com/p/android/issues/detail?id=33293
当我正在阅读时知道我看到我可以更好地描述这个问题:)

这是造成问题的提交: https : //github.com/android/platform_frameworks_base/commit/32c3a6929af9d63de3bf45a61be6e1a4bde136d3

不幸的是,我还没有find任何解决办法,除了恢复提交,我离开了它。
我希望有人会find解决办法。

你有两个fastScrollEnabledfastScrollAlwaysVisible设置为true ? 没有一个ListView fastScrollAlwaysEnabled属性,所以我想也许你只是fastScrollEnabled设置为true,但fastScrollAlwaysVisible设置为其默认值,这是false

你可以检查这个代码:

 int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion <= android.os.Build.VERSION_CODES.FROYO){ // Do something for froyo and above versions list.setFastScrollEnabled(true); } else if(currentapiVersion > android.os.Build.VERSION_CODES.HONEYCOMB){ // do something for phones running an SDK before froyo list.setFastScrollEnabled(true); list.setFastScrollAlwaysVisible(true); } 

活动

 import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.os.Bundle; import android.widget.AlphabetIndexer; import android.widget.ListView; import android.widget.SectionIndexer; import android.widget.SimpleCursorAdapter; public class TestAct extends Activity { /** Called when the activity is first created. */ ListView test_listView; Cursor myCursor; String[] proj; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_app_test); TestDummyData cTestDummyData = new TestDummyData( getApplicationContext()); cTestDummyData.open(); cTestDummyData.insertRandomNames(); myCursor = cTestDummyData.fetchAllData(); test_listView = (ListView) findViewById(R.id.pager_list_test); test_listView.setFastScrollEnabled(true); test_listView.setAdapter( new MyCursorAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, myCursor, new String[] { TestDummyData.KEY_NAME },// names new int[] { android.R.id.text1 }) ); cTestDummyData.close(); } class MyCursorAdapter extends SimpleCursorAdapter implements SectionIndexer { AlphabetIndexer alphaIndexer; // HashMap<String, Integer> alphaIndexer; // String[] sections; public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { super(context, layout, c, from, to); alphaIndexer = new AlphabetIndexer(c, myCursor.getColumnIndex(TestDummyData.KEY_NAME), " ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // ======optional way to get alphaindexer from data // alphaIndexer = new HashMap<String, Integer>(); // int size = items.size(); // // for (int x = 0; x < size; x++) { // String s = items.get(x); // // String ch = s.substring(0, 1); // // ch = ch.toUpperCase(); // // alphaIndexer.put(ch, x); // } // // Set<String> sectionLetters = alphaIndexer.keySet(); // // ArrayList<String> sectionList = new ArrayList<String>( // sectionLetters); // // Collections.sort(sectionList); // // sections = new String[sectionList.size()]; // // sectionList.toArray(sections); } @Override public int getPositionForSection(int section) { // TODO Auto-generated method stub return alphaIndexer.getPositionForSection(section); } @Override public int getSectionForPosition(int position) { // TODO Auto-generated method stub return alphaIndexer.getSectionForPosition(position); } @Override public Object[] getSections() { // TODO Auto-generated method stub return alphaIndexer.getSections(); } } } 

类使用虚拟数据列表

 import java.util.Random; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class TestDummyData { static final String KEY_ID = "_id"; static final String KEY_NAME = "name"; private static final String DB_NAME = "tutorial"; private static final String TABLE_NAME = "names"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_CREATE = "create table " + TABLE_NAME + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_NAME + " varchar not null);"; private Context context; private DatabaseHelper dbHelper; private SQLiteDatabase db; public TestDummyData(Context context) { this.context = context; this.dbHelper = new DatabaseHelper(this.context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DB_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.v("DBUTIL", "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); } } public void open() { db = dbHelper.getWritableDatabase(); } public void close() { dbHelper.close(); } public void insertRandomNames() { db.execSQL("DELETE FROM " + TABLE_NAME); String s = "ANDROIDDEVELOPER"; Random r = new Random(); ContentValues values = new ContentValues(); for (int i = 0; i < 200; i++) { values.clear(); values.put(KEY_NAME, s.substring(r.nextInt(s.length()))); db.insert(TABLE_NAME, null, values); } } public Cursor fetchAllData() { return db.rawQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY " + KEY_NAME + " ASC", null); } } 

上面的类是普通任务的虚拟数据… list_app_test.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/pager_list_test" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ListView> </LinearLayout> 

你只是给了test_listView.setFastScrollEnabled(true); gvn ans whter我cn了解你的追求。