简体   繁体   中英

QuickContactBadge in Custom Dialog

I am trying to use QuickContactBadge in custom dialog. When I try to modify qcb, it always crash, but I can´t find why. Can anyone help? Thank you in advance.

custom_xml.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<QuickContactBadge 
android:id="@+id/quickContactBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/quick_contact_badge"
android:padding="5dp"
></QuickContactBadge>
</RelativeLayout>

Java code:

Dialog dialog = new Dialog(NameOfActivity.this);
dialog.setContentView(R.layout.custom_xml);
dialog.show();

QuickContactBadge qcb = (QuickContactBadge) findViewById (R.id.quickContactBadge); 
//This make app always crash
qcb.setMode(ContactsContract.QuickContact.MODE_LARGE); 
qcb.assignContactFromPhone("12345678", true);  
qcb.setImageResource(R.drawable.icon);

You must be getting a NullPointerException . Call findViewById() on dialog object.

QuickContactBadge qcb = (QuickContactBadge) 
                                 dialog.findViewById (R.id.quickContactBadge);

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