Search ListView仅返回第一个项目

时间:2016-07-11 10:13:38

标签: android

当我搜索ListView时,即使其他项匹配,它也只返回第一项。我的代码如下,您的帮助将不胜感激。

View view = inflater.inflate(R.layout.fragment_01_rooms, container, false);

            ListView lv =(ListView)view.findViewById(R.id.listView);

            arrRequest_Title = new ArrayList<String>();
            arrRequest_Members =new ArrayList<String>();


            adapter = new RoomsAdapter(getActivity(), arrRequest_Title, arrRequest_Members);
            lv.setAdapter(adapter);

            ll = (LinearLayout)view.findViewById(R.id.ll);
            ll.setVisibility(View.GONE);
            inputSearch = (EditText) view.findViewById(R.id.inputSearch);
            inputSearch.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                    // When user changed the Text
                    Fragment_01_Rooms.this.adapter.getFilter().filter(cs); 

                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                        int arg3) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub

                }
            });

从上面的代码中,下面的代码是进行搜索的代码:

Fragment_01_Rooms.this.adapter.getFilter().filter(cs); 

更新 - RoomsAdapter类:

             class RoomsAdapter extends ArrayAdapter<String>
            {

             @Override
             public void clear() {
                 super.clear();

                 arrRequest_Title.clear();
                 arrRequest_Members.clear();
             }
                Context context;
                List<String> Request_Title;
                List<String> Request_Members;

                RoomsAdapter(Context c, List<String> Request_Title, List<String> Request_Members)
                {
                    super(c, R.layout.activity_rooms_single, R.id.textTitle, Request_Title);
                    this.context=c;
                    this.Request_Title=Request_Title;
                    this.Request_Members=Request_Members;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    // TODO Auto-generated method stub

                    View row=convertView;
                    if(row==null)
                    {
                    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    row = inflater.inflate(R.layout.activity_rooms_single, parent, false);      
                    }

                    TextView txtTitle = (TextView) row.findViewById(R.id.textTitle);
                    TextView txtMembers = (TextView) row.findViewById(R.id.textMembers);

                    txtTitle.setText(Request_Title.get(position));
                    txtMembers.setText(Request_Members.get(position));

                    return row;
                    }
                }

0 个答案:

没有答案