Android中的Combobox

Mar*_*ark 14 android combobox

我需要在android中访问类似于组合框的东西,我想选择每个名字的客户,但在后台应该选择id.怎么做?

eLo*_*ato 26

在android组合框中称为微调器.然而,gnugu在他的博客中发布了他自己的组合框实现.http://www.gnugu.com/node/57

旋转器的一个简单示例如下.首先,使用类似的东西编辑XML代码

Spinner android:id="@+id/Spinner01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Run Code Online (Sandbox Code Playgroud)

你的java代码应该包含这样的东西,选项非常直观.如果你正在使用eclipse,它会建议你一些选择

public class SpinnerExample extends Activity {
    private String array_spinner[];
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Here come all the options that you wish to show depending on the
        // size of the array.
        array_spinner=new String[5];
        array_spinner[0]="option 1";
        array_spinner[1]="option 2";
        array_spinner[2]="option 3";
        array_spinner[3]="option 4";
        array_spinner[4]="option 5";
        Spinner s = (Spinner) findViewById(R.id.Spinner01);
        ArrayAdapter adapter = new ArrayAdapter(this,
        android.R.layout.simple_spinner_item, array_spinner);
        s.setAdapter(adapter);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 如何基于所选ID创建值列表?一个包含名称的字符串列表,另一个包含id的int列表.将微调器链接到名称列表.然后,当您在微调器中选择一个项目时,在整数列表中查找所选的ID以获取所选人员的ID. (2认同)