如何使用Android Spinner对象加载其他活动?

时间:2012-01-11 10:37:56

标签: android android-activity android-spinner

我想要一个微调器,当从微调器中选择一个项目时,它应该加载已经设置的相应java页面。我们在android中从spinner中选择一个项目时加载一个java页面如果是这样我们怎么能实现这个可以任何一个提供一些示例代码

3 个答案:

答案 0 :(得分:2)

你可以

.setOnItemSelectedListener(new OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int position, long arg3) {
                    switch(position) {
                                            //Use cases to set Intents
                                            } 


                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // Do Nothing
                }
            });

答案 1 :(得分:1)

String[] items ={“One”,“Two”,“Three”,“Four”,“Five”};

Spinner sp = (Spinner)findViewById(R.id.Spinner01); 
ArrayAdapter<String> adapter = 
        new ArrayAdapter<String> (this, 
        android.R.layout.simple_spinner_item,items);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
      switch(position){
case 0:
//call first class
break;
case 1:
//call second class
break;
case 2:
//call third class
break;
case 3:
//call fourth class
break;
default:
break;
    }


    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
//nothing selected from spinner
    }
});

答案 2 :(得分:0)

只需使用spinner.onItemSelectedListener(new OnItemSelectedListener())

并在onItemSelected(AdapterView adapterview,View视图,int position,long id)方法体中编写逻辑以根据位置开始新活动。