0

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) {}`
4

2 回答 2

1

我喜欢它与三个阵列。仅测试代码:

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++;
                    }
                }
于 2013-05-06T08:26:57.610 回答
0

发生这种情况是因为 Android 只为您提供当前看到的项目的 ID + 可能两个隐藏在按钮上,两个隐藏在顶部。

教程中,您可以看到如何使用模型创建 ListView,这对我有帮助,当我之前遇到这个问题时。将此添加到您的代码中并进行更改(我认为您不需要复选框)。

于 2013-05-06T07:08:36.197 回答