spinner

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.3 kB
3
Indexable
Never
Spinner örnek

<string-array name="sehirler">
        <item>Edirne</item>
        <item>İstanbul</item>




spinnerSehir=findViewById(R.id.spinnerSehir);

 String [] sehirler=getResources().getStringArray(R.array.sehirler);
       /* ArrayAdapter<String> stringArrayAdapter=new ArrayAdapter<String>(getApplicationContext(),
                android.R.layout.simple_list_item_1,sehirler);*/
        ArrayAdapter<String> stringArrayAdapter=new ArrayAdapter<String>(getApplicationContext(),
                R.layout.spinner_goruntu,sehirler);
        spinnerSehir.setAdapter(stringArrayAdapter);
        spinnerSehir.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MainActivity.this, ""+position, Toast.LENGTH_SHORT).show();
                tvSehirler.setText(sehirler[position]);
            }

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

            }
        });
        
        
        
     btnNormalToast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // Toast.makeText(getApplicationContext(), "Normal Toast", Toast.LENGTH_SHORT).show();
                Toast.makeText(MainActivity.this,"Normal",Toast.LENGTH_SHORT).show();
            }
        });
        btnResimliToast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImageView resim = new ImageView(MainActivity.this);
                resim.setImageResource(R.drawable.resim1);
                Toast toast = new Toast(getApplicationContext());
                toast.setView(resim);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setMargin(0, 0);
                toast.show();
            }
        });
        btnOzelYaziToast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView yazi = new TextView(getApplicationContext());
                yazi.setText("ÖZel Yazı");
                yazi.setAllCaps(true);
                yazi.setTextColor(Color.RED);
                yazi.setTextSize(25);
                yazi.setBackgroundColor(Color.YELLOW);
                Toast toast = new Toast(getApplicationContext());
                toast.setView(yazi);
                toast.setDuration(Toast.LENGTH_LONG);
                //  toast.setMargin(0,-50);
                toast.setGravity(1, 150, 0);
                toast.show();
            }
        });
        btnOzelekran.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater layoutInflater = getLayoutInflater();
                View goruntu = layoutInflater.inflate(R.layout.ozel_ekran, (ViewGroup) findViewById(R.id.ozelEkran));
                Toast toast = new Toast(getApplicationContext());
                toast.setView(goruntu);
                toast.setDuration(Toast.LENGTH_LONG);
                //  toast.setMargin(0,-50);
                toast.setGravity(1, 150, 0);
                toast.show();
            }
        });
        btnSesli.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                Toast.makeText(MainActivity.this, "Ses açıldı", Toast.LENGTH_SHORT).show();
            }
        });
        btnSessiz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                Toast.makeText(MainActivity.this, "Sessiz", Toast.LENGTH_SHORT).show();
            }
        });
        btnSesTitresim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                Toast.makeText(MainActivity.this, "Titreşim", Toast.LENGTH_SHORT).show();
            }
        });