Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get contact list in list view in android?
    primarykey
    data
    text
    <p>i want to retrieve all contacts from the phone to our own list view but the code is opening the phone's contact list...this is my code for the class i am using to get the contacts..i am using contact button to fire the event and get the contacts in my list view but a null pointer exception at line marked by <em>*</em> is occurring...<br> KINDLY HELP ME. thanks in advance</p> <pre><code> public class BusinessCardActivity extends Activity { private static final int PICK_CONTACT_REQUEST = 1; private final ContactAccessor mContactAccessor = ContactAccessor.getInstance(); ImageButton contact_button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.allbuttons); LinearLayout rlayout=new LinearLayout(this); rlayout.setOrientation(LinearLayout.VERTICAL); //RelativeLayout relativeLayout= (RelativeLayout)findViewById(R.layout.main); //RelativeLayout relateLayout=(RelativeLayout)findViewById(R.layout.allbuttons); LayoutInflater layoutInflater = getLayoutInflater(); rlayout.addView(layoutInflater.inflate(R.layout.main,null)); rlayout.addView(layoutInflater.inflate(R.layout.allbuttons,null)); //pickContact(); // Install a click handler on the Pick Contact button contact_button=new ImageButton(getApplicationContext()); *** contact_button = (ImageButton)findViewById(R.id.button_contacts); contact_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pickContact(); } }); this.setContentView(rlayout); } protected void pickContact() { startActivityForResult(mContactAccessor.getPickContactIntent(), PICK_CONTACT_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PICK_CONTACT_REQUEST &amp;&amp; resultCode == RESULT_OK) { loadContactInfo(data.getData()); } } private void loadContactInfo(Uri contactUri) { AsyncTask&lt;Uri, Void, ContactInfo&gt; task = new AsyncTask&lt;Uri, Void, ContactInfo&gt;() { @Override protected ContactInfo doInBackground(Uri... uris) { return mContactAccessor.loadContact(getContentResolver(), uris[0]); } @Override protected void onPostExecute(ContactInfo result) { bindView(result); } }; task.execute(contactUri); } protected void bindView(ContactInfo contactInfo) { TextView displayNameView = (TextView) findViewById(R.id.display_name_text_view); displayNameView.setText(contactInfo.getDisplayName()); TextView phoneNumberView = (TextView)findViewById(R.id.phone_number_text_view); phoneNumberView.setText(contactInfo.getPhoneNumber()); } } . </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload