Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
33
Indexable
Never
package sumago.androidipt.autospinner;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Spinner;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    //declaration
    Spinner spinner;
    AutoCompleteTextView actv;
    ArrayList<String> cities;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //initialization
        spinner = findViewById(R.id.spinner);
        actv = findViewById(R.id.ac_tv);
        cities = new ArrayList<String>();

        cities.add("Nashik");
        cities.add("Malegaon");
        cities.add("Jalna");
        cities.add("Kannad");
        cities.add("Mumbai");
        cities.add("Pune");

        ArrayAdapter<String> citiesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, cities);
        spinner.setAdapter(citiesAdapter);
        
        actv.setAdapter(citiesAdapter);

    }
}
Leave a Comment