这是我的代码:
public class MainActivity extends Activity {
Spinner spin;
TextView tex;
String[] country = {"A", "Afghanistan", "Albania", "Etc"};// A to Z country names
String[] code = {"+93", "+91", "Etc"}; // A to Z country Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spin = (Spinner)findViewById(R.id.spinner1);
tex = (TextView)findViewById(R.id.tex);
ArrayAdapter aa1 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, country);
aa1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setPrompt("Select the Country");
spin.setAdapter(aa1);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
tex.setText(code[arg2]);
// tex.setText(country[arg2]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
我想在微调器上按字母顺序显示国家/地区列表。在此之前它应该显示 A、B、C 到 Z。但是这个 A 到 Z 在微调器列表中必须是不可选择的模式。我怎样才能做到这一点?