Search code examples
androidspinner

How to select preselect value in spinner


I have a task to develop a spinner base application which is relating to database. When I first create the application it selects the value from the spinner. After that, I have to fetch that value as a select value in a spinner I search for it a lot but I can't found it.


Solution

  •     spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                // this gets the item from adapter: parent.getItemAtPosition(pos)
                textView.setText(parent.getItemAtPosition(pos).toString());
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });