Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击微调器元素android_Java_Android_Android Spinner_Onitemclick - Fatal编程技术网

Java 单击微调器元素android

Java 单击微调器元素android,java,android,android-spinner,onitemclick,Java,Android,Android Spinner,Onitemclick,我在main.xml中创建了一个微调器: <Spinner android:id="@+id/spinner1" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/categoria_arrays" android:prompt="@string/categoria_p

我在main.xml中创建了一个微调器:

<Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/categoria_arrays"
        android:prompt="@string/categoria_prompt" />

我该怎么做?

您需要显式设置微调器的侦听器

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1,
        // your code here
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        // your code here
    }
}); 
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
//你的代码在这里
}
未选择公共无效(AdapterView arg0){
//你的代码在这里
}
}); 

您需要显式设置微调器的侦听器

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1,
        // your code here
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        // your code here
    }
}); 
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
//你的代码在这里
}
未选择公共无效(AdapterView arg0){
//你的代码在这里
}
}); 

您需要显式设置微调器的侦听器

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1,
        // your code here
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        // your code here
    }
}); 
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
//你的代码在这里
}
未选择公共无效(AdapterView arg0){
//你的代码在这里
}
}); 

您需要显式设置微调器的侦听器

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1,
        // your code here
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        // your code here
    }
}); 
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
//你的代码在这里
}
未选择公共无效(AdapterView arg0){
//你的代码在这里
}
}); 

是的,这是可能的。像这样做吧

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        if (pos == 1){
                Intent i = new Intent(currentActivity.this, One.class);
                startActivity(i);

        }else if (pos == 2)
        {
                Intent i = new Intent(currentActivity.this, Two.class);
                startActivity(i);

        }else if (pos == 3){
                Intent i = new Intent(currentActivity.this, Three.class);
                startActivity(i);
      }
      }
public void已选择(AdapterView父视图、视图视图、整数位置、长id){
如果(位置==1){
意图i=新意图(currentActivity.this,One.class);
星触觉(i);
}否则如果(位置==2)
{
意图i=新意图(currentActivity.this,Two.class);
星触觉(i);
}否则如果(位置==3){
意向i=新意向(currentActivity.this,Three.class);
星触觉(i);
}
}

等等…

是的,这是可能的。像这样做吧

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        if (pos == 1){
                Intent i = new Intent(currentActivity.this, One.class);
                startActivity(i);

        }else if (pos == 2)
        {
                Intent i = new Intent(currentActivity.this, Two.class);
                startActivity(i);

        }else if (pos == 3){
                Intent i = new Intent(currentActivity.this, Three.class);
                startActivity(i);
      }
      }
public void已选择(AdapterView父视图、视图视图、整数位置、长id){
如果(位置==1){
意图i=新意图(currentActivity.this,One.class);
星触觉(i);
}否则如果(位置==2)
{
意图i=新意图(currentActivity.this,Two.class);
星触觉(i);
}否则如果(位置==3){
意向i=新意向(currentActivity.this,Three.class);
星触觉(i);
}
}

等等…

是的,这是可能的。像这样做吧

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        if (pos == 1){
                Intent i = new Intent(currentActivity.this, One.class);
                startActivity(i);

        }else if (pos == 2)
        {
                Intent i = new Intent(currentActivity.this, Two.class);
                startActivity(i);

        }else if (pos == 3){
                Intent i = new Intent(currentActivity.this, Three.class);
                startActivity(i);
      }
      }
public void已选择(AdapterView父视图、视图视图、整数位置、长id){
如果(位置==1){
意图i=新意图(currentActivity.this,One.class);
星触觉(i);
}否则如果(位置==2)
{
意图i=新意图(currentActivity.this,Two.class);
星触觉(i);
}否则如果(位置==3){
意向i=新意向(currentActivity.this,Three.class);
星触觉(i);
}
}

等等…

是的,这是可能的。像这样做吧

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        if (pos == 1){
                Intent i = new Intent(currentActivity.this, One.class);
                startActivity(i);

        }else if (pos == 2)
        {
                Intent i = new Intent(currentActivity.this, Two.class);
                startActivity(i);

        }else if (pos == 3){
                Intent i = new Intent(currentActivity.this, Three.class);
                startActivity(i);
      }
      }
public void已选择(AdapterView父视图、视图视图、整数位置、长id){
如果(位置==1){
意图i=新意图(currentActivity.this,One.class);
星触觉(i);
}否则如果(位置==2)
{
意图i=新意图(currentActivity.this,Two.class);
星触觉(i);
}否则如果(位置==3){
意向i=新意向(currentActivity.this,Three.class);
星触觉(i);
}
}

依此类推……

您需要如下设置项selected listener:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // your code here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
    }

});
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id){
//你的代码在这里
}
@凌驾
未选择公共无效(AdapterView父视图){
//你的代码在这里
}
});

您需要如下设置所选的项目侦听器:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // your code here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
    }

});
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id){
//你的代码在这里
}
@凌驾
未选择公共无效(AdapterView父视图){
//你的代码在这里
}
});

您需要如下设置所选的项目侦听器:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // your code here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
    }

});
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id){
//你的代码在这里
}
@凌驾
未选择公共无效(AdapterView父视图){
//你的代码在这里
}
});

您需要如下设置所选的项目侦听器:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // your code here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
    }

});
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id){
//你的代码在这里
}
@凌驾
未选择公共无效(AdapterView父视图){
//你的代码在这里
}
});

只需在setContentView之后的onCreate中调用类似的内容:

Spinner spinner = (Spinner) findViewById(R.id.spinner1);
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
                Toast.makeText(parent.getContext(), "OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
                Toast.LENGTH_SHORT).show();
                //HERE CHANGE ACTIVITY

            }

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

});
Spinner-Spinner=(Spinner)findviewbyd(R.id.spinner1);
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共位置(AdapterView父项、视图、整数位置、长id){
Toast.makeText(parent.getContext(),“OnItemSelectedListener:”+parent.getItemAtPosition(pos).toString(),
吐司。长度(短)。show();
//在这里改变活动
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
});
Sim卡