You do this using a any subclass of the BaseAdapter. Assuming you want to load data from the database you use the SimpleCursorAdapter.
String[] from = new String[]{"nameOfColumn"}; //nameOfColumn is the name of the column in cursor to display in the spinner.
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter (this, android.R.layout.simple_spinner_item, null, from, to, 0);
cursorAdapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
binding.paymentChannelSpinner.setAdapter (cursorAdapter);
binding.paymentChannelSpinner.setOnItemSelectedListener (new AdapterView.OnItemSelectedListener () {
@Override
public void onItemSelected (AdapterView<?> adapterView, View view, int i, long l) {
if (i != -1) {
Cursor c = (Cursor) adapterView.getItemAtPosition (i);
}
}
@Override
public void onNothingSelected (AdapterView<?> adapterView) {
}
});
after getting your data as a cursor from the database you will set the cursor to the adapter like this:
cursorAdapter.changeCursor(cursorFromDB);
However, if the data is in a java array you can user an Arrayadapter
ArrayAdapter
for example – Discretion