Spinner android type dropdown code example

Example 1: how to set list data to android spinner

// setting branch data in manually and load to spBranchName
        List<String> branchList = new ArrayList<>();
        branchList.add("CHITTAGONG");
        branchList.add("DHAKA");

        ArrayAdapter<String> branchListAdapter = new ArrayAdapter<>(getActivity(),
                android.R.layout.simple_spinner_item, branchList);
        branchListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spBranchName.setAdapter(branchListAdapter);

Example 2: set drop down list spinner

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.support_simple_spinner_dropdown_item, spinnerlist);
        spinner.setAdapter(adapter);

Tags:

Misc Example