QuickContactBadge dans la boîte de Dialogue personnaliser
-
29-10-2019 - |
Question
Je suis en train d'utiliser QuickContactBadge dans la boîte de dialogue personnaliser.Lorsque je tente de modifier le qcb, il toujours tomber en panne, mais je n'arrive pas à trouver pourquoi.Quelqu'un peut-il aider?Je vous remercie à l'avance.
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>
Le code Java:
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);
La solution
Vous devez être l'obtention d'un NullPointerException
.Appel findViewById()
dans la boîte de dialogue de l'objet.
QuickContactBadge qcb = (QuickContactBadge)
dialog.findViewById (R.id.quickContactBadge);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow