Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android列表视图部分索引器-列表视图不显示当前滚动字母_Android_Listview_Indexer_Fastscroll - Fatal编程技术网

Android列表视图部分索引器-列表视图不显示当前滚动字母

Android列表视图部分索引器-列表视图不显示当前滚动字母,android,listview,indexer,fastscroll,Android,Listview,Indexer,Fastscroll,我正在尝试在列表视图中使用带快速滚动的SecionIndex。 我已经实施了,但是 在列表的滚动条上,它会弹出我们滚动的当前字母, 但这并没有表现出来 在调试模式下,我知道在我的例子中从来没有调用过getSectipons()和getPositionForSection(), 但在我从web尝试的任何其他简单示例中,它都会调用这些函数 佩雷斯建议我怎么做 //################## 这是我的适配器的代码 //####################### 公共类MyListAdap

我正在尝试在列表视图中使用带快速滚动的SecionIndex。 我已经实施了,但是 在列表的滚动条上,它会弹出我们滚动的当前字母, 但这并没有表现出来

在调试模式下,我知道在我的例子中从来没有调用过getSectipons()和getPositionForSection(), 但在我从web尝试的任何其他简单示例中,它都会调用这些函数

佩雷斯建议我怎么做 //################## 这是我的适配器的代码

//#######################

公共类MyListAdapter扩展ArrayAdapter实现SectionIndexer{
活动语境;
对象[]列表数据;
HashMap字母索引器;
字符串[]段;
公共MyListAdapter(活动上下文,对象[]对象){
超级(上下文、右布局、新投资行、对象);
this.context=上下文;
listData=对象;
alphaIndexer=新HashMap();
//这里的变化
ArrayList myArrayList=新建ArrayList();
对于(int-ix=0;ix=0;i--){
最终HashMap obj=(HashMap)listData[i];
String元素=obj.get(“Name”);
alphaIndexer.put(element.substring(0,1).toUpperCase(),i);
}
Set keys=alphaIndexer.keySet();//字母集
//复制到列表中进行排序
Iterator it=keys.Iterator();
ArrayList键列表=新的ArrayList();
while(it.hasNext()){
String key=it.next();
keyList.add(key);
}
集合。排序(键列表);
//转换为数组
sections=新字符串[keyList.size()];
密钥列表。toArray(部分);
对于(intc=0;c
我假设在适配器中,当我传递textViewId时,它不会将currect textVewId作为sectionIndexer函数调用

在布局新建投资行中,我得到一个自定义行,该行有一个图标和几个文本视图。 我正在根据每行中显示的对象的名称对列表进行排序。 我希望索引器处理对象的名称


请帮我提供确切的解决方案

不,然后我为我的应用程序切换了字母搜索功能,这很有效。但是如果你想要@Minasamy,我还有其他解决方案。请分享你的解决方案@babyandroid
public class MyListAdapter extends ArrayAdapter<Object> implements SectionIndexer {

    Activity context;
    Object[] listData;
    HashMap<String, Integer> alphaIndexer;
    String[] sections;

    public MyListAdapter(Activity context, Object[] objects) {
        super(context, R.layout.new_invest_row, objects);
        this.context = context;
        listData = objects;
        alphaIndexer = new HashMap<String, Integer>();
        //changes here

         ArrayList myArrayList = new ArrayList();
           for (int ix=0; ix<objects.length; ix++) {
               myArrayList.add(objects[ix]);
               }

           Collections.sort(myArrayList, new Comparator<HashMap<String, String>>(){ 
                public int compare(HashMap<String, String> one, HashMap<String, String> two) { 
                    return one.get("Name").compareToIgnoreCase(two.get("Name"));
                } 
        });

         listData = myArrayList.toArray();
        //Arrays.sort(listData);
        for (int i = listData.length - 1; i >= 0; i--) {
            final HashMap<String, String> obj = (HashMap<String, String>)listData[i];
            String element = obj.get("Name");
            alphaIndexer.put(element.substring(0, 1).toUpperCase(), i); 
        }

        Set<String> keys = alphaIndexer.keySet(); // set of letters

        // Copy into a List for sorting
        Iterator<String> it = keys.iterator();
        ArrayList<String> keyList = new ArrayList<String>(); 
        while (it.hasNext()) {
            String key = it.next();
            keyList.add(key);
        }
        Collections.sort(keyList);

        // Convert to array
        sections = new String[keyList.size()];
        keyList.toArray(sections);
        for(int c=0;c < sections.length;c++)Log.e("secction<"+c+">","+"+sections[c]);
        Log.e("alphaIndexer","+"+alphaIndexer);
    }

    static class ViewHolder {
        TextView txtName;
        TextView txtOwner;
        TextView txtStartDate;
        TextView txtEndDate;
        TextView txtStatus;
        ImageView imgIcon;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        View rowView = convertView;

        if (rowView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.new_invest_row, null, true);
            holder = new ViewHolder();
            **holder.txtName = (TextView) rowView.findViewById(R.id.invest_row_name);**
//my custom code here

            rowView.setTag(holder);
        } else {
            holder = (ViewHolder) rowView.getTag();
        }

        @SuppressWarnings("unchecked")
        final HashMap<String, String> obj = (HashMap<String, String>)listData[position];

        String str = obj.get("Name");
        if(null == str){
            str = "";
        }
        holder.txtName.setText(str);

        //#################
               //my custom code here

        return rowView;
    }

    public int getPositionForSection(int section) {
        String letter = sections[section];
        Log.e("alphaIndexer.get(letter)","+"+alphaIndexer.get(letter));

        return alphaIndexer.get(letter);
    }

    public int getSectionForPosition(int arg0) {
        // TODO Auto-generated method stub
        return 1;
    }

    public Object[] getSections() {
        return sections;
    }
}

//#######################