- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在为实现 SectionIndexer
的 ListView
使用适配器。 ListView
在 xml 文件中将 fastScrollEnabled
设置为 true。在 Android 2.2 和 2.3 上一切正常,但是当我在装有 Android 3.0 的平板电脑上测试我的应用程序时,滚动条在某些部分消失了。例如,当我向下滚动列表时,以字母 A-B 滚动条开头的元素可见,但对于字母 C-H 则不可见,然后在 H 之后再次可见。
此适配器用于在 ListView 中按字母顺序对内容进行排序,以便可以使用 fastscroll。
应用程序是为 API Level 8 设计的,所以我不能使用 fastScrollAlwaysVisible。
这是我的适配器的代码:
public class AlphabetSimpleAdapter extends SimpleAdapter implements SectionIndexer {
private HashMap<String, Integer> charList;
private String[] alphabet;
public Typeface tfSansMedium;
public Context mContext;
public int mResource;
public int[] mTo;
public List<? extends Map<String, ?>> mData;
public String mTitleKey;
public AlphabetSimpleAdapter(Context context,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to, String titleKey /* key sent in hashmap */) {
super(context, data, resource, from, to);
mData = data;
mTitleKey = titleKey;
mContext = context;
mResource = resource;
mTo = new int[to.length];
for ( int i = 0; i < to.length; i ++)
{
mTo[i] = to[i];
}
charList = new HashMap<String, Integer>();
int size = data.size();
tfSansMedium = Typeface.createFromAsset(context.getAssets(), "fonts/VitesseSans-Medium.otf");
for(int i = 0; i < size; i++) {
// Parsing first letter of hashmap element
String ch = data.get(i).get(titleKey).toString().substring(0, 1);
ch = ch.toUpperCase();
if(!charList.containsKey(ch)) {
charList.put(ch, i); // Using hashmap to avoid duplicates
}
}
Set<String> sectionLetters = charList.keySet(); // A set of all first letters
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters); // Creating arraylist to be able to sort elements
Collections.sort(sectionList, Collator.getInstance(new Locale("pl", "PL"))); // Sorting elements
alphabet = new String[sectionList.size()];
sectionList.toArray(alphabet);
}
// Methods required by SectionIndexer
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(mResource, null);
}
for (int i = 0; i < mTo.length; i ++) {
TextView tv = (TextView)v.findViewById(mTo[i]);
if (tv != null) tv.setTypeface(tfSansMedium);
}
return super.getView(position, v, parent);
}
@Override
public int getPositionForSection(int section) {
if(!(section > alphabet.length-1)) {
return charList.get(alphabet[section]);
}
else {
return charList.get(alphabet[alphabet.length-1]);
}
}
@Override
public int getSectionForPosition(int position) {
return charList.get(mData.get(position).get(mTitleKey).toString().substring(0, 1));
}
@Override
public Object[] getSections() {
return alphabet;
}
}
charList
是一个 HashMap,我在其中存储字母及其最后出现的索引,因此当我有 6 个以字母“A”开头的元素时,键“A”的值为 5,依此类推。
alphabet
是一个包含所有现有首字母的字符串数组。
最佳答案
我遇到了同样的问题。我只是将我的最低 SDK 版本设为 8,将 traget 设为 16,并编写了以下代码。一切正常。
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion <= android.os.Build.VERSION_CODES.FROYO){
// Do something for froyo and above versions
fblist.setFastScrollEnabled(true);
} else if(currentapiVersion > android.os.Build.VERSION_CODES.HONEYCOMB){
// do something for phones running an SDK before froyo
fblist.setFastScrollEnabled(true);
fblist.setFastScrollAlwaysVisible(true);
}
关于java - 在 HoneyComb 的特定部分使用 SectionIndexer 时,滚动条消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10976549/
是否可以使用自定义 View 作为部分索引器? IE。使它更透明并使用图像而不是字符? 是否可以在不禁用 FastScroll 功能的情况下按需启用/禁用 SectionIndexer 弹出窗口? 最
有没有人找到一种方法来设置使用 SectionIndexer 时出现的小部件的样式?样式更改,例如更改文本颜色或背景颜色。 最佳答案 找到答案 here 您必须创建一个主题并将其应用于 Activit
我正在尝试找到一种方法来使用 SectionIndexer,而不是 AlphabetIndexer。我感兴趣的是在节标题而不是字母表中包含字符串数组的元素。我无法使用节索引器找到任何示例代码。 这是
我有一个包含事件的自定义 ListView。 Adapters SectionIndexer 在快速滚动(例如,星期一 10:00)时索引星期几和事件的时间,但是使用快速滚动文本的默认样式,文本太大并
我一直在寻找在我的 listView 中对日期使用 SectionIndexer 的方法。我想在快速滚动列表时显示“短日期”。我看到几年前的一篇帖子,其中一个人说他已经成功了,但他遇到了不同的问题,但
下面是我的适配器的代码,它允许创建一个弹出窗口,其中包含我的 ListView 中每个项目的首字母,并提供类似于联系人应用程序的内容。 不幸的是,颜色不正确,文本是灰色背景上的黑色。 我的问题是: 我
我创建了一个 UITableView,它使用屏幕顶部的标题 View 和顶部的字母 sectionIndex 栏。我的 sectionIndex 栏是透明的,但它似乎延伸了我的 tableView 的
在将新项目添加到 ListView 后,有什么方法可以重新索引 SectionIndexer 吗? 我找到了这个 solution , 但刷新SectionIndexer后叠加层位于左上角。 有人有什
在实现 SectionIndexer 的 ArrayAdapter 中,有代码检查以相同首字母开头的列表项——因此可以合并。 像这样: alphaIndexer = new HashMap()
我已经使用 SectionIndexer 实现了一个 ListView。它在 99% 的时间里都能正常工作,但我发现有一种情况会出错。 错误是: java.lang.ArrayIndexOutOfBo
我实现了一个 ListView ,它实现了 SectionIndexer ...到目前为止一切都很好。 通常项目按名称排序,但我也提供以不同方式排序列表的选项 - 按距离(从用户到对象)。 因此,当列
有人知道如何使用 SectionIndexer 或 RecyclerView 的替代品吗? SectionIndexer 允许 ListView 在快速滚动时弹出部分。 最佳答案 问题在于 Recyc
我有一个按月和年(2010 年 6 月、2010 年 7 月等)分隔的事件列表。我启用了快速滚动,因为列表真的很长。我还实现了 SectionIndexer,以便人们在快速向下滚动事件列表时可以看到他
我写了一个实现 SectionIndexer 接口(interface)的 BaseAdapter 并且一切正常,我可以使用我的 ListView 的 setFastScrollingEnabled(
我正在从 PHChange 实例修改我的 UITableView 的数据源,这工作正常。我不明白的是,我无法更新 UITableView 右侧的 sectionIndex,除非您使用以下方法重新加载整
我使用实现了 SectionIndexer 的自定义适配器来创建 ListView。当我在 list 文件中仅键入 minSdkVersion = 8 时,一切正常。但是,如果我将 targetSdk
如何设置 UITableView 右侧 sectionIndex 的字体大小? 最佳答案 Try this solution, this will definitely help you -> Ste
我创建了一个使用 FastScroll 的 ListView。 (见图片)当用户单击以下任何按钮(即所有轨道、艺术家、专辑)时,每次调用以下自定义 ArrayAdater ArrayAdapter a
I created 3 headerViews and added check box, when select section0 check box i want to expand cells i
有没有办法以编程方式禁用/启用分段? 所以我可以在普通的 fastScroll 和 Indexes 之间进行选择,而无需制作两个适配器? 最佳答案 我终于自己找到了它。您只需将带有字母的数组设为空,瞧
我是一名优秀的程序员,十分优秀!