在过滤了一个列表视图后,我怎样才能获得第一个列表视图的位置?[英] After filter a listview,how can I obtain the position of the first listview?

本文是小编为大家收集整理的关于在过滤了一个列表视图后,我怎样才能获得第一个列表视图的位置?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

过滤列表视图后,如何获得第一个listView的位置? 我使用SimpleAdapter填充ListView. 数据源中的每个项目都有自己的ID,我使用"案例"重定向. 过滤列表视图后,我不知道如何将后一个项目与第一个listView关联.帖子和ID已更改. 谢谢.

我使用EditTextView的后纹理量进行过滤列表视图并通知它.

            @Override
        public void afterTextChanged(Editable paramEditable) {

            listItemsCopy.clear();
            int count=simpleAdapter.getCount();
            if ((count>0 )&&paramEditable.length()>0) {
                for (int i = 0; i < simpleAdapter.getCount(); i++) {
                    Map<String,Object> tempMap=(Map<String,Object>)simpleAdapter.getItem(i);
                    String itemName=tempMap.get("name").toString();
                    HashMap<String, Object> tempHashMap=new HashMap<String, Object>();
                    int copyCount=0;
                    if(itemName.toLowerCase().contains(paramEditable.toString().toLowerCase())){

                        tempHashMap=(HashMap<String, Object>)simpleAdapter.getItem(i);
                        listItemsCopy.add(tempHashMap);

                        copyCount++;
                    }
                }                       

        if(listItemsCopy!=null){
        Handler handler=new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                simpleAdaptercopy = new SimpleAdapter(getActivity(),
                        listItemsCopy, R.layout.right_menu_list_view, new String[] {
                                "name", "id", "image" }, new int[] {
                                R.id.rightMenuListViewTextView1,
                                R.id.rightMenuListViewTextView2,
                                R.id.rightMenuListViewImageView1 });

                simpleAdapter.setViewBinder(new ViewBinder() {

                    @Override
                    public boolean setViewValue(View view, Object data,
                            String textRepresentation) {
                        if ((view instanceof ImageView && data instanceof Bitmap)) {
                            ImageView iv = (ImageView) view;
                            iv.setImageBitmap((Bitmap) data);
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
                listView.setAdapter(simpleAdaptercopy);
                simpleAdapter.notifyDataSetChanged();


                                }
        }, 1000);
        }
            }
            else {
                listView.setAdapter(simpleAdapter);
                simpleAdapter.notifyDataSetChanged();
            }
        }

然后,我想使用listView的方法onitemclick重定向不同的意图.数据源已更改,位置和ID都不同,我想要

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Intent intent = null;
            switch (position) {}`

推荐答案

我用三个阵列将其划过.仅测试代码:

String positionString[]=new String[22];
                int latterPosition[]=new int[22];
                for (int i = 0; i < latterPosition.length; i++) {
                    positionString[i]="";
                    latterPosition[i]=0;
                }
                int latterCount=0;
                for (int i = 0; i < positions.length; i++) {
                    if (positions[i]==10) {
                        positionString[latterCount]=i+"";
                        latterPosition[latterCount]=10;
                        latterCount++;
                    }
                }

其他推荐答案

这发生了,因为Android为您提供了当前看到的ITMES的ID +可能隐藏在按钮上的两个,而两个隐藏在顶部.

in this 您可以看到如何使用listview创建listview一个模型,当我遇到这个问题时,这对我有帮助.将其添加到您的代码并更改它(我认为您不需要复选框).

本文地址:https://www.itbaoku.cn/post/102789.html

问题描述

After filter a listview,how can I obtain the position of the first listview? I use simpleadapter to fill the listview. Each item in the datasource has its own id,and I use "case" to redirect them. After I filter the listview ,I don't know how to associate the latter items with the first listview.The postion and id have changed. Thank you.

I use the afterTextChanged of EditTextView to filter the listview and notify it.

            @Override
        public void afterTextChanged(Editable paramEditable) {

            listItemsCopy.clear();
            int count=simpleAdapter.getCount();
            if ((count>0 )&&paramEditable.length()>0) {
                for (int i = 0; i < simpleAdapter.getCount(); i++) {
                    Map<String,Object> tempMap=(Map<String,Object>)simpleAdapter.getItem(i);
                    String itemName=tempMap.get("name").toString();
                    HashMap<String, Object> tempHashMap=new HashMap<String, Object>();
                    int copyCount=0;
                    if(itemName.toLowerCase().contains(paramEditable.toString().toLowerCase())){

                        tempHashMap=(HashMap<String, Object>)simpleAdapter.getItem(i);
                        listItemsCopy.add(tempHashMap);

                        copyCount++;
                    }
                }                       

        if(listItemsCopy!=null){
        Handler handler=new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                simpleAdaptercopy = new SimpleAdapter(getActivity(),
                        listItemsCopy, R.layout.right_menu_list_view, new String[] {
                                "name", "id", "image" }, new int[] {
                                R.id.rightMenuListViewTextView1,
                                R.id.rightMenuListViewTextView2,
                                R.id.rightMenuListViewImageView1 });

                simpleAdapter.setViewBinder(new ViewBinder() {

                    @Override
                    public boolean setViewValue(View view, Object data,
                            String textRepresentation) {
                        if ((view instanceof ImageView && data instanceof Bitmap)) {
                            ImageView iv = (ImageView) view;
                            iv.setImageBitmap((Bitmap) data);
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
                listView.setAdapter(simpleAdaptercopy);
                simpleAdapter.notifyDataSetChanged();


                                }
        }, 1000);
        }
            }
            else {
                listView.setAdapter(simpleAdapter);
                simpleAdapter.notifyDataSetChanged();
            }
        }

Then I want to use the method onItemClick of listview to redirect different Intent.As the datasource has changed,both position and id are different from which I want

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Intent intent = null;
            switch (position) {}`

推荐答案

I slove it with three arrays. Only test code:

String positionString[]=new String[22];
                int latterPosition[]=new int[22];
                for (int i = 0; i < latterPosition.length; i++) {
                    positionString[i]="";
                    latterPosition[i]=0;
                }
                int latterCount=0;
                for (int i = 0; i < positions.length; i++) {
                    if (positions[i]==10) {
                        positionString[latterCount]=i+"";
                        latterPosition[latterCount]=10;
                        latterCount++;
                    }
                }

其他推荐答案

this happens becouse Android gives you only IDs for the itmes you currently see + maybe two hidden on button and two hidden on top.

In this tutorial you can see how to create a ListView with a model, this helps me, when i got this problem before. Add this to you code and change it (I think you don't need the checkboxes).