Skip to content

Instantly share code, notes, and snippets.

@dsibinski
Created May 9, 2017 21:26
Show Gist options
  • Save dsibinski/a90e6c8d63e5226dd9c2d3bb1f94db61 to your computer and use it in GitHub Desktop.
Save dsibinski/a90e6c8d63e5226dd9c2d3bb1f94db61 to your computer and use it in GitHub Desktop.
public class PeopleListFragment : ListFragment
{
private List<Person> _peopleList;
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
InitializePeopleList();
}
public override void OnStart()
{
base.OnStart();
InitializePeopleList();
}
protected async void InitializePeopleList()
{
_peopleList = await GetPeopleAsync();
this.ListAdapter = new ArrayAdapter<string>(Activity, Android.Resource.Layout.SimpleListItem1, _peopleList.ConvertAll(p => p.ToString()));
InitializeUserControlsEvents();
}
private async Task<List<Person>> GetPeopleAsync()
{
var repo = new Repository<Person>();
var people = await repo.GetAll();
return people.ToList();
}
private void InitializeUserControlsEvents()
{
this.ListView.ItemClick += ListView_ItemClick;
}
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
var person = _peopleList[e.Position];
var uri = Android.Net.Uri.Parse("tel:" + person.PhoneNumber);
var intent = new Intent(Intent.ActionDial, uri);
StartActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment