What I want to do is that when I load the content that exists inside the Spinner I am loaded in a textview, this is the code where all the data of the spinner is executed, as extra data is connected to a MySQL database.
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;
}
}
And here is the 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();
}
}
I just want to load the spinner in the textview that appears here, thank you very much