微调监听器不工作 [英] Spinner listener not working

查看:93
本文介绍了微调监听器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这个code的应用程序崩溃..它并不甚至启动..任何想法家伙感谢
我的这个code的应用程序崩溃..它并不甚至启动..任何想法家伙感谢

my app crashes with this code.. it doesnt even start up.. any ideas guys thanks my app crashes with this code.. it doesnt even start up.. any ideas guys thanks

package com.about.bysk;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.Toast;

public abstract class AboutActivity extends Activity implements
        OnItemSelectedListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinner spinner = (Spinner) findViewById(R.id.spin);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                Toast.makeText(null, "a", 5);

            }

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

            }
        });
    }
}

这让我的应用程序崩溃。请帮助..

this makes my app crash. please help..

推荐答案

您必须设置监听器为您的微调和你的类必须实现 OnItemSelectedListener

You have to set Listener for your spinner and your class must implement OnItemSelectedListener

public class YourClass extends Activity implements OnItemSelectedListener { ... }

然后你必须设置监听器为您的微调:

spinner.setOnItemSelectedListener(this);

或者你可以使用它像匿名类

Or you can use it like anonymous class

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

    @Override
    public void onNothingSelected(AdapterView<?> parentView) { ... }
});

注意:如果你想显示吐司,则必须调用显示()

Note: If you want to show Toast, you must call show() method.

这篇关于微调监听器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆