试图在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);
}
它抛出一个错误,说"Syntax error on token "setDropDownViewResource", identifier expected after this token.
此外,spinner.setAdapter(adapter);
也不起作用。
有人可以帮我解决这个问题吗?