Вызов 4 методов один за другим в Android

Я хочу знать, как я могу назвать 4 ментодов один за другим в Android. например:

начать с метода getSim ()

метод getSim () после завершения запускает метод getPhone ()

метод getPhone () после завершения запускает метод сравнения ()

Метод сравнения (), когда завершено запуск метода отображения ()

 private void getSim()
    {
        System.out.println("In get Sim");
        Uri simUri = Uri.parse("content://icc/adn"); 

        Cursor cursorSim = context.getContentResolver().query(simUri,null,null,null,null);

        Log.i("PhoneContact", "total: "+cursorSim.getCount());
        if(cursorSim.getCount()>0)
        {
            while (cursorSim.moveToNext()) 
            {      
                ClsSimPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
                ClsSimphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
                String xyz= ClsSimphoneNo.replaceAll("\\D","").replaceAll("&", "").replaceAll("\\(","").replaceAll("\\)","").replaceAll("\\s", "").replaceAll("-", "");
                Log.i("PhoneContact", "name: "+ClsSimPhonename+" phone: "+ClsSimphoneNo);
                   // getSimPhone.add(ClsSimPhonename+" sim");
                    getSimPhone.add(ClsSimPhonename);
                    mb.add(xyz);
            }
            cursorSim.close();
        }
    }`


`private void getPhone(){
        cr = getContentResolver();
        Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        if(cursor.getCount()>0)
        {   
           while (cursor.moveToNext())
           {
               String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
               name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

               if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) 
               {
                   Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                          ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{id}, null);

                   while (pCur.moveToNext())
                   {
                       phone = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        mbnum =phone.replaceAll("\\(","").replaceAll("\\)","").replaceAll("\\s", "").replaceAll("-", "");
                       mb.add(mbnum);


                   }
                   pCur.close();
               }

               getSimPhone.add(name+" ph");



            }
            cursor.close();
        }
    }`

` private void compare()
{ParseQuery<ParseUser> query = ParseUser.getQuery();

            query.whereNotEqualTo("objectId", currentUserId);
            query.findInBackground(new FindCallback<ParseUser>() 
            {
                public void done(List<ParseUser> userList, com.parse.ParseException e)
                {
                    if (e == null) 
                    {
                        for (int i=0; i<userList.size(); i++) 
                        {
                            names.add(userList.get(i).getUsername().toString());
                            ph.add(userList.get(i).getString("mobile"));
                        }

                        for(int z=0;z<mb.size();z++)
                        {
                            for (int i=0; i<ph.size(); i++)     
                            {
                                if(mb.get(z).equals(ph.get(i)))
                                {
                                 Toast.makeText(ShowContactsWithApp.this,"z mb"+mb.get(z)+ "\n i ph"+ph.get(i) + "\n z name" +getSimPhone.get(z)+"\n i name"+getSimPhone.get(i),Toast.LENGTH_LONG).show();
                                    values.add(getSimPhone.get(z));
                                 Toast.makeText(ShowContactsWithApp.this,"got a record",Toast.LENGTH_SHORT).show();
                                }
                            }
                        }
                        Toast.makeText(ShowContactsWithApp.this,"values count :"+values.size(),Toast.LENGTH_SHORT).show();

                    }
                    else 
                    {
                       Toast.makeText(ShowContactsWithApp.this,"Error loading user list",Toast.LENGTH_SHORT).show();
                    }
                 }
            });
            return values;
        }
}`

`display ()
 adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1, values);
                        lst.setAdapter(adapter);`

Во-первых, я получаю сим-контакты, во-вторых, я получаю телефонные контакты, в третьем я сравниваю с разбором сохраненных контактов и в четвертом я отображаю сравнение.

2 ответа

Вы просто делаете это:

myMethod1();
myMethod2();
myMethod3();
myMethod4();

Попробуй вот так

  A(){
   //here do your coding. at the end call next method
   //here  you can call your method B
   B();
   }

  B(){
   //here do your coding. at the end call next method
  //here  you can call your method C
  C();
  }
  C(){
   //here do your coding. at the end call next method
  //here  you can call your method D
  D();
  }

  D(){
   //here do your coding.
    }
Другие вопросы по тегам