您的位置:首页 > 其它

下拉菜单字段值对应编号。通过相应编号得到字段值。

2015-12-09 14:37 330 查看
/**

* 提供存放在文件夹下的属性文件作为单表查询结果展示 的字段集

* @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) {
}
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: