"spinner android" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "spinner android" answered properly. Developers are finding an appropriate answer about spinner android related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like spinner android. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on spinner android.
spinner android
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Business Services");
categories.add("Computers");
categories.add("Education");
categories.add("Personal");
categories.add("Travel");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
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);
how to access a spinner from another activity in android
First save the position of selected data from spinner in a String variable,
int positionOfSelectedDataFromSpinner;
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
positionOfSelectedDataFromSpinner= position;
}
Then on button click send intent to Another activity with putExtra
Intent i = new Intent (this, activity2.class);
i.putExtra("position", positionOfSelectedDataFromSpinner);
startActivity(i);
get int from getIntent in another activity
Intent intent = getIntent();
int positionToShowToSpinner = intent.getStringExtra("position");
then set the position to spinner
spinner.setSelection(positionToShowToSpinner);
I think this my solve your problem.
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on spinner android can get a collection of related answers to their query. Programmers need to enter their query on spinner android related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about spinner android for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of spinner android while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "spinner android". Visit this developer's friendly online web community, CodeProZone, and get your queries like spinner android resolved professionally and stay updated to the latest Whatever updates.