Created
June 23, 2014 21:54
-
-
Save Cheesebaron/9f7cde5abe9db28214fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App1.App1" android:versionCode="1" | |
android:versionName="1.0" android:installLocation="auto"> | |
<application android:label="App1" android:icon="@drawable/Icon"></application> | |
<uses-permission android:name="android.permission.READ_CONTACTS" /> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<Button | |
android:text="Select Contact" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/contactButton" /> | |
<TextView | |
android:text="Selected Contact" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
<TextView | |
android:id="@+id/selectedContact" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Frag : Fragment | |
{ | |
private TextView _selectedContact; | |
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) | |
{ | |
var view = inflater.Inflate(Resource.Layout.Frag, container, false); | |
var button = view.FindViewById<Button>(Resource.Id.contactButton); | |
button.Click += (s, e) => | |
{ | |
var intent = new Intent(Intent.ActionPick, ContactsContract.Contacts.ContentUri); | |
StartActivityForResult(intent, 9001); | |
}; | |
_selectedContact = view.FindViewById<TextView>(Resource.Id.selectedContact); | |
return view; | |
} | |
public override void OnActivityResult(int requestCode, int resultCode, Intent data) | |
{ | |
if (requestCode == 9001 && resultCode == (int) Result.Ok) | |
{ | |
if (data == null || data.Data == null) | |
return; | |
var addressBook = new Xamarin.Contacts.AddressBook(Activity) | |
{ | |
PreferContactAggregation = false | |
}; | |
var contact = addressBook.Load(data.Data.LastPathSegment); | |
_selectedContact.Text = contact.FirstName; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:id="@+id/content"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")] | |
public class MainActivity : FragmentActivity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
base.OnCreate(bundle); | |
// Set our view from the "main" layout resource | |
SetContentView(Resource.Layout.Main); | |
SupportFragmentManager.BeginTransaction() | |
.Replace(Resource.Id.content, new Frag()) | |
.Commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment