Aller au contenu

Recuperer les données des EDIT TEXT et SPINNER


GND

Recommended Posts

Bonjour,

je suis debutant, je crée un programme perso, sauf que j'ai des difficultés pour recuperer les données des EditText et des Spinner pour les afficher dans un autre EditText afin de l'envoie comme sms.

Aide moi, S'il vous plait

package com.example.medalerte;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.text.BreakIterator;
import java.util.ArrayList;

public class ActivityMed extends AppCompatActivity {

private EditText Nomosa;
private EditText Adres;
private Button Verifier;
private Button Envoyer;
private EditText Affichage;

    Spinner sp_cat, sp_eta, sp_med, sp_zone, sp_prov;

    ArrayList<String> arrayList_cat;
    ArrayList<String> arrayList_eta;
    ArrayList<String> arrayList_zone;
    ArrayList<String> arrayList_prov;


    ArrayAdapter<String> arrayAdapter_cat;
    ArrayAdapter<String> arrayAdapter_eta;
    ArrayAdapter<String> arrayAdapter_zone;
    ArrayAdapter<String> arrayAdapter_prov;


    ArrayList<String> arrayList_Mal, arrayList_lose, arrayList_IH;
    ArrayAdapter<String> arrayAdapter_med;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_med);

Nomosa = (EditText)findViewById(R.id.etNomosa);
Adresse=(EditText)findViewById(R.id.etAdres);
Verifier = (Button)findViewById(R.id.btnVer);
Envoyer = (Button)findViewById(R.id.btnEnvoie);
Affichage = (TextView) findViewById(R.id.txtAffichi);



sp_cat=(Spinner)findViewById(R.id.sp_cat);
sp_eta=(Spinner)findViewById(R.id.sp_eta);
sp_med=(Spinner)findViewById(R.id.sp_med);
sp_prov=(Spinner)findViewById(R.id.sp_prov);
sp_zone=(Spinner)findViewById(R.id.sp_zone);


arrayList_cat=new ArrayList<>();
arrayList_cat.add("Selectionner");
arrayList_cat.add("Mal");
arrayList_cat.add("lose");
arrayList_cat.add("IH");

arrayAdapter_cat=new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_spinner_item, arrayList_cat);
sp_cat.setAdapter(arrayAdapter_cat);

arrayList_eta=new ArrayList<>();
arrayList_eta.add("Selectionner");
arrayList_eta.add("Rupture");
arrayList_eta.add("Pture");

arrayAdapter_eta=new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_spinner_item, arrayList_eta);
sp_eta.setAdapter(arrayAdapter_eta);

arrayList_zone=new ArrayList<>();
arrayList_zone.add("Selectionner");
arrayList_zone.add("BANDALUNGWA");
arrayList_zone.add("BARUMBU");
arrayList_zone.add("BINZA MÉTÉO");
arrayList_zone.add("BINZA OZONE");


arrayAdapter_zone=new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_spinner_item, arrayList_zonesante);
sp_zone.setAdapter(arrayAdapter_zone);


arrayList_prov=new ArrayList<>();
arrayList_prov.add("Selectionner");
arrayList_prov.add("BAS");
arrayList_prov.add("TEUR");
arrayList_prov.add("HAUT");




arrayAdapter_prov=new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_spinner_item, arrayList_province);
sp_prov.setAdapter(arrayAdapter_prov);

//***** med spinner process starts ****

arrayList_Mal=new ArrayList<>();
arrayList_Mal.add("Selectionner");
arrayList_Mal.add("tesunate");
arrayList_Mal.add("modiaquinem");


arrayList_lose=new ArrayList<>();
arrayList_lose.add("Selectionner");
arrayList_lose.add("Isoniazid");
arrayList_lose.add("Isoniazidmg");



arrayList_IH=new ArrayList<>();
arrayList_IH.add("Selectionner");
arrayList_IH.add("Abacavir");
arrayList_IH.add("Lamivudine");
arrayList_IH.add("Dolutegravir");
arrayList_IH.add("Efavirenz");
sp_cat.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

if(position==1)
        {
arrayAdapter_med=new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item,arrayList_Mal);
        }

if(position==2)
        {
arrayAdapter_med=new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item,arrayList_lose);
        }

if(position==3)
        {
arrayAdapter_med=new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item,arrayList_IH);
        }

sp_med.setAdapter(arrayAdapter_med);
    }

@Override
public void onNothingSelected(AdapterView<?> parent) {

    }
});

//***** med spinner process ends ****
}
Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...