[英]How to add a title bar in Android while sorting?
Here is my code: 这是我的代码:
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
}
});
}
}
I want to display the country's list in alphabetic order on spinner. 我想在微调框上按字母顺序显示该国家/地区的列表。 And before that it should display the A, B, C up to Z. But This A to Z must be unselectable mode in spinner list. 在此之前,它应该显示A,B,C直到Z。但是,此A到Z必须是微调器列表中的不可选择模式。 How can I achieve that? 我该如何实现?
You'll have to create your custom adapter that extends the ArrayAdapter. 您必须创建扩展ArrayAdapter的自定义适配器。
it will probably be very easy, something like: 这可能非常简单,例如:
// the get view on your adapter
getView(LayoutInflater, etc, etc){
convertView = super.getView(inflater, etc, etc);
if(getItem(position).equals("A") || getItem(position).equals("B") || // etc, or create some clever way to go through a ArrayList with just the letters ){
convertView. // set not clickable stuff
}
}
but I reckon the Spinner still will close the list whenever the user clicks. 但我认为Spinner仍然会在用户单击时关闭列表。 Maybe you must override the spinner OnItemClick to get a coherent behaviour. 也许您必须重写微调器OnItemClick才能获得连贯的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.