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 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