Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created August 12, 2017 19:25
Show Gist options
  • Save gavilanch/c683677c7e39db0c39b5f5a5c61ef1a2 to your computer and use it in GitHub Desktop.
Save gavilanch/c683677c7e39db0c39b5f5a5c61ef1a2 to your computer and use it in GitHub Desktop.
// En NewsListActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.NewsList);
var newsListView = FindViewById<ListView>(Resource.Id.newsListView);
var newsService = new NewsService();
var news = newsService.GetNews();
newsListView.Adapter = new NewsListAdapter(this, news);
newsListView.ItemClick += NewsListView_ItemClick;
}
private void NewsListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
var intent = new Intent(this, typeof(MainActivity));
var id = (int)e.Id;
intent.PutExtra(MainActivity.KEY_ID, id);
StartActivity(intent);
}
// En el MainActivity.cs
internal static string KEY_ID = "KEY_ID";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
var id = Intent.Extras.GetInt(KEY_ID);
var newsService = new NewsService();
var news = newsService.GetNewsById(id);
var newsTitle = FindViewById<TextView>(Resource.Id.newsTitle);
var newsBody = FindViewById<TextView>(Resource.Id.newsBody);
var newsImage = FindViewById<ImageView>(Resource.Id.newsImage);
var display = WindowManager.DefaultDisplay;
Android.Graphics.Point point = new Android.Graphics.Point();
display.GetSize(point);
var imageURL = string.Concat(ValuesService.ImagesBaseURL,
news.ImageName);
Picasso.With(ApplicationContext)
.Load(imageURL)
.Resize(point.X, 0)
.Into(newsImage);
newsTitle.Text = news.Title;
newsBody.Text = news.Body;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment