Lo que quiero hacer es que cuando cargue el contenido que exista dentro del Spinner se me cargue en un textview, este es el codigo donde se ejecuta todos los datos del spinner, como dato extra esta conectado a una base de datos MySQL.
class DataParser : AsyncTask
{
Context c;
private Spinner sp;
private String jsonData;
JavaList<string> spacecrafts=new JavaList<string>();
private ProgressDialog pd;
public DataParser(Context c, Spinner sp, string jsonData)
{
this.c = c;
this.sp = sp;
this.jsonData = jsonData;
}
protected override void OnPreExecute()
{
base.OnPreExecute();
pd = new ProgressDialog(c);
pd.SetTitle("Cargando información");
pd.SetMessage("Por favor espere");
pd.Show();
}
protected override Object DoInBackground(params Object[] @params)
{
return this.ParseData();
}
protected override void OnPostExecute(Object result)
{
base.OnPostExecute(result);
pd.Dismiss();
if (Integer.ParseInt(result.ToString()) == 0)
{
Toast.MakeText(c,"No se puede analizar",ToastLength.Short).Show();
}
else
{
ArrayAdapter<string> adapter=new ArrayAdapter<string>(c,Android.Resource.Layout.SimpleListItem1,spacecrafts);
sp.Adapter = adapter;
sp.ItemSelected += sp_ItemSelected;
}
}
void sp_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Toast.MakeText(c, spacecrafts[e.Position], ToastLength.Short).Show();
}
private int ParseData()
{
try
{
JSONArray ja=new JSONArray(jsonData);
JSONObject jo = null;
spacecrafts.Clear();
for (int i = 0; i < ja.Length(); i++)
{
jo = ja.GetJSONObject(i);
String name = jo.GetString("nomb_ingrediente");
spacecrafts.Add(name);
}
return 1;
}
catch (Exception e)
{
Console.WriteLine(e);
}
return 0;
}
}
Y acá esta el MainActivity
public class MainActivity : Activity
{
private Spinner sp;
private String urlAddress = "localhost:7777/carpeta/buscar.php";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
sp = FindViewById<Spinner>(Resource.Id.sp);
TextView text = FindViewById<TextView>(Resource.Id.textView1);
Button downloadBtn = FindViewById<Button>(Resource.Id.downloadBtn);
downloadBtn.Click += downloadBtn_Click;
}
void downloadBtn_Click(object sender, EventArgs e)
{
new Downloader(this, urlAddress, sp).Execute();
}
}
Solo quiero cargar el spinner en el textview que aparece acá, muchas gracias