Android Programming Tutorials

(Romina) #1
Look Inside Yourself

android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="2px"
android:paddingTop="2px"
android:paddingBottom="2px"
android:paddingRight="5px"
/>
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:textSize="11pt"
android:paddingTop="2px"
android:paddingBottom="2px"
/>
</RelativeLayout>

Then, let's implement onActivityResult() on Contacter to get the selected


contact, get access to the PackageManager, craft an empty Intent on the


selected contact, and query the PackageManager for available activities that


work with that Intent. Finally, we sort the resulting list of ResolveInfo


objects and pour them into an ActionAdapter:


@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode==PICK_REQUEST) {
if (resultCode==RESULT_OK) {
Uri contact=data.getData();
Intent stub=new Intent();

stub.setData(contact);

PackageManager pm=getPackageManager();
List<ResolveInfo> actions=pm.queryIntentActivities(stub, 0 );

Collections.sort(actions,
new ResolveInfo.DisplayNameComparator(pm));

setListAdapter(new ActionAdapter(pm, actions));
}
}
}

309
Free download pdf