[英]How to add a title bar in Android while sorting?
這是我的代碼:
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必須是微調器列表中的不可選擇模式。 我該如何實現?
您必須創建擴展ArrayAdapter的自定義適配器。
這可能非常簡單,例如:
// 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
}
}
但我認為Spinner仍然會在用戶單擊時關閉列表。 也許您必須重寫微調器OnItemClick才能獲得連貫的行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.