android spinner 總結

來源:互聯網
上載者:User

本次項目中tabhost中使用spiner遇到的問題,總結一下。

首先在頁面onCreate的時候需要改變的是:

View contentView = LayoutInflater.from(getParent().getParent()).inflate(R.layout.personal_information, null);
setContentView(contentView);

這樣的方式來設定頁面顯示的view.

personalProvinceSpinner = (Spinner) contentView.findViewById(R.id.personalProvinceSpinner); 這樣的方式來擷取spinner控制項對象

 其次定義適配器:

private ArrayAdapter<CharSequence> provinceAdapter = null;

初始化:

List<CharSequence> planets = new ArrayList<CharSequence>();  如果需要實現動態更新適配器的值必須用動態集合來定義,不然planets可以是String數組對象

provinceAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, planets);
personalProvinceSpinner.setPromptId(R.string.setting_dialog_checkprovince);
provinceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
personalProvinceSpinner.setAdapter(provinceAdapter);

//設定預設選中

personalProvinceSpinner.setSelection(index, true);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.