how to fill spinner or dropdown in android studio | how to use spinner in android studio
android dropdown|android dropdown list|custom spinner android|spinner in android studio|spinner android|spinner android studio|android spinner example|dropdown in android studio
Paste this code within onCreate
Spinner spinner = findViewById(R.id.spinHintQuest);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("Select Hint Question");
arrayList.add("Favourite food");
arrayList.add("Favourite color");
arrayList.add("nick name");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arrayList);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String tutorialsName = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), "Selected: " + tutorialsName, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});