实现多个微调器

时间:2014-05-20 06:16:59

标签: android spinner

我正在尝试添加多个微调器但是当我尝试选择它时显示空白透明对话框...

这是代码,我试过请帮助。

(在onCreate之外)

public void onItemSelected(AdapterView<?> parent, View view, int position,
        long id) {

     switch(parent.getId()){
        case R.id.spinner1:
            ArrayAdapter arrayadapter = new ArrayAdapter(VideoPlaybackActivity.this,android.R.layout.simple_spinner_dropdown_item,vlaues);  
         arrayadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
           spiner.setAdapter(arrayadapter);


        spiner.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {
                 String s1= spiner.getSelectedItem().toString();
                   timer.setText(s1);
             }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub

            }
         }
        );

            break;
        case R.id.spinner2:
            ArrayAdapter arrayadapter1 = new ArrayAdapter(VideoPlaybackActivity.this,android.R.layout.simple_spinner_dropdown_item,typeArray);  
             arrayadapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
               spinner2.setAdapter(arrayadapter1);


            spinner2.setOnItemSelectedListener(new OnItemSelectedListener()
            {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view,
                        int position, long id) {
                     String s1= spinner2.getSelectedItem().toString();

                 }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    // TODO Auto-generated method stub

                }
             }
            );
            break;
    }
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
    // TODO Auto-generated method stub

}

这里是值和typeArray

    String vlaues[] = {"1","2","3","4","5","6","7","8","9","10"};

  String typeArray[] = {"pic1","pic2","pic3"};

我试图在微调器上显示这两个数组....

1 个答案:

答案 0 :(得分:1)

它只是应用程序逻辑中的错误。在选择了微调器项后设置微调器适配器:

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    switch(parent.getId()){
    case R.id.spinner1:
        ArrayAdapter arrayadapter = ... 
        spiner.setAdapter(arrayadapter);
        spiner.setOnItemSelectedListener(new OnItemSelectedListener(){...});
        break;

...

在获取onItemSelected回调之前,您需要为微调器设置适配器和OnItemSelectedListener。