下拉菜單字段值對應編號。通過相應編號得到字段值。

/**
* 提供存放在文件夾下的屬性文件作爲單表查詢結果展示 的字段集
* @param path 屬性文件的路徑
* @return Bean實體封裝類(String,String)
*/
public List getBeansList(String path) {
String Path = String.format(“data/%s.properties”, path);
List optionList = new ArrayList();
try {
InputStream in = getAssets().open(Path);
/**Util類中寫入getBeanList方法,解析相應的.properties文件
* 此處省略了該類方法;
*/
return optionList = Util.getBeanList(in);
} catch (IOException e) {
return null;
}
}

/**
 * 提供存放在a文件夾下的屬性文件作爲下拉選的數據源
 * @param path 屬性文件的路徑*(%s.properties)文件 
 * @param id 佈局文件中下拉選的id
 */
public void getOption(String path, int id) {
    List<Bean> optionList = new ArrayList<Bean>();
    try {
        InputStream in = getAssets().open(path);
        /**Util類中寫入getBeanList方法,解析相應的.properties文件
         * 此處省略了該類方法;
        */
        optionList = Util.getBeanList(in);
    } catch (IOException e) {
    }

    Spinner me_Spinner = (Spinner) findViewById(id);
    ArrayAdapter<String> adapter = new ArrayAdapter(this,
            android.R.layout.simple_spinner_item, optionList);
    adapter.setDropDownViewResource(R.layout.spinner_drop_item);
    me_Spinner.setAdapter(adapter);
    me_Spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            View focus = parent.getSelectedView();
            focus.setFocusable(true);
            focus.setSelected(true);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章