Search code examples
androidlistlistviewcontactsselectall

contact on list view with select all option and search option on android


contact on list view with select all option and search option on android i have tried a lot of ways but no matter to find a list view with name,phone no and check box for everyone and also a select all button and search option

public void onTextChanged(CharSequence s,int start, int before, int count)
                    {
                        textlength = et.getText().length();
                    //  et.setText(textlength);
                        if(et.getText().toString().equalsIgnoreCase("helloo")){
                        //  Toast.makeText(getApplicationContext(),"jd",1000).show();
                            for (int i = 0; i < name1.size(); i++)
                            {
                            if (textlength <= name1.size())
                            {
                                Toast.makeText(getApplicationContext(),"searching.....inside",1000).show();
                            if(et.getText().toString().equalsIgnoreCase((String)((CharSequence) name1).subSequence(0,textlength)))
                            {
                            //  array_sort.addAll(name1);
                                                                                                                            }
                                                                                                            }

                                if(et.getText().toString().equalsIgnoreCase(
                                        (String)(CharSequence) name1)){
                                    Toast.makeText(getApplicationContext(),"searching.....",1000).show();
                                }

                                }
                            lv.setAdapter(new ArrayAdapter<String>
                            (contact_fetch.this,
                                    android.R.layout.simple_list_item_1, array_sort));


                        }
                    }
                });

Solution

  • I had the same problem.Finally I solved with this code. Hope It will help you :)

        //layout function
        public void lay_out(List<String> exp1,int k){
        LayoutInflater layoutInflater = 
                    (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    container.removeAllViews();
                    for(int i=0;i<exp1.size();i++){     
                        final View addView = layoutInflater.inflate(R.layout.row, null);
                        TextView tv=(TextView)addView.findViewById(R.id.textView1);
                        final CheckBox cb=(CheckBox) addView.findViewById(R.id.checkbox1);
                        if(k==0)
                            {
                                cb.setChecked(false);
                            }
                        else
                            {
                                cb.setChecked(true);
                            }
                        tv.setText(name1.get(i));
                        cb.setText(phno1.get(i));
                        container.addView(addView);
                        cb.setOnClickListener(new View.OnClickListener() {
    
                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                //  Toast.makeText(getApplicationContext(),cb.getText().toString(),10).show();
                                if(cb.isChecked()==true){ 
                                    if(checkedcontacts.length()<0)
                                    {
                                        for(int i=0;i<=checkedcontacts.length();i++)
                                        {
                                            if(!checkedcontacts.equals(cb.getText().toString()))
                                            {
                                                // insertion
                                                checkedcontacts.append(cb.getText().toString());
                                                checkedcontacts.append("\n");
                                            }
                                        }
                                    }
                                    else{
                                    checkedcontacts.append(cb.getText().toString());
                                    checkedcontacts.append("\n");
                                    }
                                }
                                else if(cb.isChecked()==false){
                                    s_all.setChecked(false);
                                    try{
                                        Toast.makeText(getApplicationContext(),cb.getText().toString(),10).show();
                                        //Pattern.compile(cb.getText().toString()).matcher(checkedcontacts).replaceAll("");
                                            checkedcontacts.delete(checkedcontacts.indexOf(cb.getText().toString()),
                                                    cb.getText().toString().length());
                                    }
                                    catch(Exception e){
                                        System.out.println("error on array"+e);
                                    }
                                }
                            }
                        });
                container.setVisibility(View.VISIBLE);
                       }
        }