简体   繁体   中英

getting contact number from contactlist in Android but dont work equals()

I'm really confused . I want to get the phone numbers and save a arrays

To do this I use the following function

public void PickContact(){

       Cursor phones = BaseContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
       NameContacts=new String[phones.getCount()];

     int i=0;
       while (phones.moveToNext())
        {

         NameContacts[i]=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

         i++;
        }

}

This method works properly

I would , if the contact name with a particular name , A message will display .

Part of the code

   {
  String Contacts="";

    Show_Contact.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            for(int i=0;i<NameContacts.length;i++)
               Contacts+=NameContacts[i];
            text.setText(Contacts);

        }
    });
       //show all Name Contact in textView



    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        for(int i=0;i<NameContacts.length;i++)
        {
            if(NَameContacts[i].equals("aaa"));
                Toast.makeText(getBaseContext(), ""+NumberContacts.length, Toast.LENGTH_LONG).show();


        }
}
    });
    //dont show Toast

but No message is displayed!! The statement if, any time is not true!!!!!!!!

Names that are stored in Contact my phone .

"ahmad", "ferank", "المختار" , "مونس", "anjeli" ,"aaa",...

Having two languages ​​, a list of contact, no problem ????

the problem is the semicolon after the if statement.

This should work:

if(NameContacts[i].equals("aaa"))
    Toast.makeText(getBaseContext(), ""+NumberContacts.length, Toast.LENGTH_LONG).show();

But i recommend to explicitly use the curly brackets:

if(NameContacts[i].equals("aaa")) {
    Toast.makeText(getBaseContext(), ""+NumberContacts.length, Toast.LENGTH_LONG).show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM