0

我有一个(简单的)二维数组。我想做的是用该数组中的数据填充微调器。

String ap1[][] = new String[5][2];
ap1[0][0]="First item";
ap1[0][1]="1";
ap1[1][0]="Second item";
ap1[1][1]="2";
//etc. etc. etc.

Spinner apSpinner = (Spinner) findViewById(R.id.ap_spinner);

现在微调器应该填充来自每个数组条目的第一个元素(例如“第一个项目”、“第二个项目”、...),并且应该在做出选择后读取第二个项目并在以后的计算中使用。

我尝试使用以下代码,但得到了一些奇怪的文本,例如 LJava.Lang.String;@...

ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, ap1);
apSpinner.setAdapter(spinnerArrayAdapter);

关于我的问题的任何线索?

4

1 回答 1

1

Adding a dimension to the array makes your life harder. If you goal of your 2nd dimension is to

should be read after a selection has been made and used in later

You can achieve/get the same number in position+1 . Depending one when/how you will use it.

You also have to remember, what you see in your list (Docs):

To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.

So you will see String[].toString() , since its the 2nd dimension. Hence you see classname@hashcode

于 2013-02-04T21:21:20.253 回答