2

我在将侦听器添加到微调器时遇到问题。当我单击一些微调器的项目时,什么也没有发生。这是我的代码:

    Button button_marker= (Button) findViewById(R.id.button_markers);
    ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this, R.array.markers, android.R.layout.simple_spinner_item);
    spinner= new Spinner(this);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);    
    spinner.setAdapter(adapter);

    button_marker.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            spinner.performClick();
        }
    });

new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            Log.e("klkl", "klkl");

        }

        public void onNothingSelected(AdapterView<?> arg0) {
            Log.e("klkl", "klkl");


        }
    });
4

3 回答 3

6
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                 Log.e("klkl", "klkl");

            }

            public void onNothingSelected(AdapterView<?> arg0) {
                Log.e("klkl", "klkl");

            }
        });
于 2012-09-29T08:42:59.737 回答
0

尝试使用

spinner .OnItemSelectedListener() {

    public void onItemSelected(AdapterView<?> arg0, View arg1,
            int arg2, long arg3) {
        Log.e("klkl", "klkl");

    }

    public void onNothingSelected(AdapterView<?> arg0) {
        Log.e("klkl", "klkl");


    }
});
于 2012-09-28T17:33:54.747 回答
0

您的微调器执行点击,而不是项目选择。尝试这个:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1,
            int arg2, long arg3) {
        Log.e("klkl", "klkl");
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        Log.e("klkl", "klkl");
    }
}); 
于 2013-01-28T21:31:48.070 回答