Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8888767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:06:32+00:00 2026-06-14T22:06:32+00:00

I want the phonenumber to be loaded into string xx…how is it possible??How to

  • 0

I want the phonenumber to be loaded into string xx”…how is it possible??How to share data between methods?? I have tried to make the method public but that wont help….I know the activity starts from main activity…so how is it possible to get data from another method and then process main activity?

public class MsgcontactActivity extends Activity {

    private static final int CONTACT_PICKER_RESULT = 1001;
    public void doLaunchContactPicker(View view) 
    {  
        Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);  
        startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);  
    }

    EditText phoneTxt;
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView) findViewById(R.id.textView1);
        String xx=phoneTxt.getText().toString();
        Toast.makeText(getApplicationContext(), xx,Toast.LENGTH_LONG ).show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    {  
         String phone="";
         Cursor contacts=null;
         try
         {
            if (resultCode == RESULT_OK) 
            {  
                switch (requestCode) 
                {  
                    case CONTACT_PICKER_RESULT:  
                        Uri result = data.getData();
                        String id = result.getLastPathSegment(); 
                        contacts=getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id },  null);
                        int phoneIdx = contacts.getColumnIndex(Phone.DATA); 
                        if (contacts.moveToFirst()) 
                        {
                           phone = contacts.getString(phoneIdx);  
                           EditText phoneTxt=(EditText)findViewById(R.id.phoneno);
                           phoneTxt.setText(phone);
                        } 
                        else 
                        {  
                           Toast.makeText(this, "error", 100).show();
                        }  
                        break;  
                    }
                }
                else 
                {
                    Toast.makeText(this, "Warning: activity result not ok",50).show();
                }  
            }
            catch (Exception e) 
            {  
                Toast.makeText(this, e.getMessage(), 50).show();  
            } 
            finally 
            {  
                if (contacts != null) 
                {  
                    contacts.close();  
                }
            }
        }
    }   
}

XML Code:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText  
        android:layout_height="wrap_content"  
        android:id="@+id/phoneno"  
        android:inputType="text|phone"  
        android:layout_width="wrap_content"  
        android:layout_toLeftOf="@+id/Contacts"  
        android:layout_alignParentLeft="true"/>
    <Button  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:id="@+id/Contacts"  
        android:text="Contacts"  
        android:layout_alignParentRight="true" 
        android:onClick="doLaunchContactPicker"/>
    <TextView 
        android:text="TextView" 
        android:layout_width="wrap_content" 
        android:id="@+id/textView1" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/phoneno" 
        android:layout_alignParentLeft="true"/>

</RelativeLayout>

Next Try

public class MsgcontactActivity extends Activity {

private static final int CONTACT_PICKER_RESULT = 1001;
public void doLaunchContactPicker(View view) 
    {  
        Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);  
        startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);  

    }

EditText phoneTxt;
        Button b;
TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
                b=(Button) findViewById(R.id.button1);
        tv=(TextView) findViewById(R.id.textView1);
        b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                doLaunchContactPicker(v);

            }
        });



        String xx=phoneTxt.getText().toString();
        tv.setText(xx);
}


    @Override
    public void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        {  
             String phone="";
             Cursor contacts=null;
             try
             {
                if (resultCode == RESULT_OK) 
                {  
                    switch (requestCode) 
                    {  
                    case CONTACT_PICKER_RESULT:  

                     Uri result = data.getData();

                     String id = result.getLastPathSegment(); 

                     contacts=getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id },  null);

                     int phoneIdx = contacts.getColumnIndex(Phone.DATA); 
                     if (contacts.moveToFirst()) 
                     {

                           phone = contacts.getString(phoneIdx);  

                           EditText phoneTxt=(EditText)findViewById(R.id.editText1);

                           phoneTxt.setText(phone);     

                        } 
                     else 
                     {  
                      Toast.makeText(this, "error", 100).show();
                        }  
                     break;  
                    }  

                } 
                else 
                {  

                    Toast.makeText(this, "Warning: activity result not ok",50).show();  

                }  
            }
             catch (Exception e) 
             {  
                Toast.makeText(this, e.getMessage(), 50).show();  
                } 
             finally 
             {  
                if (contacts != null) 
                {  
                    contacts.close();  
                }
             }
    }
    }

}

HTML code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
<EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_alignParentTop="true" android:layout_alignParentLeft="true">
    <requestFocus></requestFocus>
</EditText>
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/editText1" android:layout_marginLeft="33dp"></Button>
<TextView android:text="TextView" android:layout_width="wrap_content" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"></TextView>
 </RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:06:33+00:00Added an answer on June 14, 2026 at 10:06 pm

    Call this doLaunchContactPicker() method after setContentView(R.layout.main); in onCreate() method and if you don’t use view in doLaunchContactPicker() method then don’t pass View as a parameter in method and add this line Button btn=(Button) findViewById(R.id.Contacts); after setContentView(R.layout.main);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Uhm, so I have run into this before. I want to do this. PhoneNumber
set phoneNumber 1234567890 this number single digit, i want divide this number into 123
I have an Excel file containing data(list of Phone numbers), and i want that
I want to replace a string in a vector string. I mean, I have
I have an ArrayList of firms with firmId, firmName,address,phoneNumber,status fields. I want to dynamically
I have the following data which I want to save in my DB (this
I have a string of numbers and I want to print the first, first
I want to search data from nsdictionary based on different criteria.Say I have 4
I want to dial a number from IPhone simulator for India. I have tried
I have a phone number I want to match against a regular expression. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.