I'm having some challenges regarding collecting a selected value from a ListActivity. In my work I will depend on pick lists to fill a form and so will be jumping back and forth. In my old VB days this would have consisted of simply making up a form a then capturing a result event back to the caller. In my searching I cant really fin anything similar and was hoping someone here might help. I have an Activity1 that calls and activity 2 but how do I get the selected text in Activity2 back to Activity1 just by selecting the list item. My two parts are listed below.
I'm Stumped.
using System;
using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS;
namespace AndroidApplication2 { [Activity(Label = "AndroidApplication2", MainLauncher = true, Icon = "@drawable/icon")] public class Activity1 : Activity { Button btnRun; // = FindViewById
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate
{
var second = new Intent(this, typeof(Picklist));
second.PutExtra("SQL", "Select CODE,text from picklist where LIST ='species'");
StartActivityForResult(second, 100);
};
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok)
{
var imageView = FindViewById<ImageView>(Resource.Id.btnRun);
}
}
}
using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget;
namespace AndroidApplication2 { [Activity(Label = "Pick List", MainLauncher = true, Icon = "@drawable/icon")] public class Picklist : ListActivity { string[] items; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); string cSQL; cSQL = Intent.GetStringExtra("SQL") ?? "Data not available"; localhost.Service1 client = new localhost.Service1(); client.Url = "http://10.0.2.2:15021/Service1.svc"; client.GetRecordsCompleted += _Result; client.GetRecordsAsync(cSQL, "|"); }
void _Result(object sender, localhost.GetRecordsCompletedEventArgs e)
{
items = e.Result.Split('|');
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
}
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
//base.OnListItemClick(l, v, position, id);
Toast.MakeText(this, items[position],ToastLength.Short).Show();
return;
}
}
}