Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ACTIVITY 1
- sing Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Widget;
- using Java.Net;
- using System;
- using System.IO;
- using System.Json;
- using System.Net;
- using System.Security.Policy;
- using System.Threading.Tasks;
- namespace Prova
- {
- [Activity(Label = "Prova", MainLauncher = true)]
- public class MainActivity : Activity
- {
- JsonValue MyResult;
- JsonValue[] Indice;
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- // Set our view from the "main" layout resource
- SetContentView(Resource.Layout.PorcaMadonna);
- Button MyButton = FindViewById<Button>(Resource.Id.button1);
- EditText MyText = FindViewById<EditText>(Resource.Id.textView1);
- ListView MyList = FindViewById<ListView>(Resource.Id.listView1);
- MyButton.Click += async (sender, e) =>
- {
- string url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant+in+" + MyText.Text + "&key=METTERELAKEY";
- JsonValue json = await FetchMethodAsync(url);
- MyResult = json["results"];
- string[] items = new string[MyResult.Count];
- int i = 0;
- Indice = new JsonValue[MyResult.Count];
- foreach (JsonValue x in MyResult)
- {
- items[i] = x["name"];
- Indice[i] = x;
- i++;
- }
- MyList.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
- MyList.ItemClick += MyList_ItemClick;
- };
- }
- private void MyList_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Intent MyIntent = new Intent(this, typeof(activity2));
- MyIntent.PutExtra("Ciao", Indice[e.Position].ToString());
- StartActivity(MyIntent);
- }
- private async Task<JsonValue> FetchMethodAsync(string url)
- {
- string c = url;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
- request.ContentType = "application/json";
- request.Method = "GET";
- using (WebResponse response = await request.GetResponseAsync())
- {
- using (Stream stream = response.GetResponseStream())
- {
- JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
- return jsonDoc;
- }
- }
- }
- }
- }
- //ACTIVITY 2
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Json;
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- namespace Prova
- {
- [Activity(Label = "activity2")]
- public class activity2 : Activity
- {
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- SetContentView(Resource.Layout.layout1);
- TextView MyText1 = FindViewById<TextView>(Resource.Id.textView1);
- TextView MyText2 = FindViewById<TextView>(Resource.Id.textView2);
- JsonValue A = (JsonValue)Intent.GetStringExtra("Ciao");
- MyText1.Text = A["name"];
- MyText2.Text = A["formatted_address"];
- // Create your application here
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement