开发者

Spinner values vs text?

Imagine an app that has a spinner menu with values 1,2,3,4 etc, b开发者_如何学Cut in text. In HTML you'd specify both the value, and the displayed text:

1 One

2 Two

3 Three

etc, and you can then make the interface pleasing to users, but easy for the app to extract the value (e.g. 3, not Three)

I need a drop-down menu in an Android app that shows text equivalents of numeric values. How do I display the right text, but then easily extract the right value behind it? I don't want to use the position, as that is prone to bugs if the contents are changed.


create two List object one contain the display value and another contain the actual value for e.g.

List<String> disp_list = new ArrayList<String>();

disp_list contains [one, two, three]

List<String> actual_list = new ArrayList<String>();

actual_list contains [1,2,3]

now when user select get the position value on change listener of spinner and get the actual value form the actual_list

select in spinner is "two" and it's index value is 1;

String sel = "";

for e.g.

spinner.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int index, long position) {
// TODO Auto-generated method stub
     sel = actual_list.get(index);
}
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜