我想创建一个快速滚动的联系人列表。在右边我需要放置字母列表“ABCD ... Z”。在屏幕上,我需要弹出A或B ...每次我点击右侧列表或向上和向下滚动。
在我的代码中:我有两个问题: 首先,当我向下滚动列表a时,字母列表图像消失 其次,如果我在列表中间单击,屏幕上不会出现任何内容。我的意思是我需要将我的取景器放在滚动按钮上,以便在浏览列表时查看下方列表字符。当滚动显示时我不想要那个按钮,我也希望它在我放置取景器的地方激活。
有什么建议吗?
的.java
class MyIndexerAdapter<T> extends ArrayAdapter<T> implements SectionIndexer {
ArrayList<String> myElements;
HashMap<String, Integer> alphaIndexer;
String[] sections;
public MyIndexerAdapter(Context context, int textViewResourceId,
List<T> objects) {
super(context, textViewResourceId, objects);
myElements = (ArrayList<String>) objects;
// here is the tricky stuff
alphaIndexer = new HashMap<String, Integer>();
// in this hashmap we will store here the positions for
// the sections
int size = elements.size();
for (int i = size - 1; i >= 0; i--) {
String element = elements.get(i);
alphaIndexer.put(element.substring(0, 1), i);
//We store the first letter of the word, and its index.
//The Hashmap will replace the value for identical keys are putted in
}
Set<String> keys = alphaIndexer.keySet(); // set of letters ...sets
Iterator<String> it = keys.iterator();
ArrayList<String> keyList = new ArrayList<String>(); // list can be
// sorted
while (it.hasNext()) {
String key = it.next();
keyList.add(key);
}
Collections.sort(keyList);
sections = new String[keyList.size()]; // simple conversion to an
// array of object
keyList.toArray(sections);
}
public int getPositionForSection(int section) {
// Log.v("getPositionForSection", ""+section);
String letter = sections[section];
return alphaIndexer.get(letter);
}
public int getSectionForPosition(int position) {
// you will notice it will be never called (right?)
Log.v("getSectionForPosition", "called");
return 0;
}
public Object[] getSections() {
return sections; // to string will be called each object, to display }
}
}