Trying to make a spinner in android:
package com.example.test;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.BaseAdapter;
public class SpinnerBuilding extends Activity {
Spinner spinner = (Spinner) findViewById(R.id.building);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.buildings_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
}
It throws an error saying "Syntax error on token "setDropDownViewResource", identifier expected after this token. Moreover, the spinner.setAdapter(adapter); also does not work.
Could somebody help me with this??
You need to move the whole code inside some method, You cannot execute code from outside of method in a class.
Preferably move the whole code inside Oncreate.