开发者

Button+Spinner [android]

开发者 https://www.devze.com 2023-01-22 20:46 出处:网络
I used a spinner and a button inside a tab of my application but, when I assigned a onClicklistner for my button

I used a spinner and a button inside a tab of my application

but, when I assigned a onClicklistner for my button

the application crashes.

i used

myspinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView adapter, View v, 
         int i,longlng) {
    }
});

for my spinner and

 btn.setOnClickListener(new OnClickListener() {
    @Override
    public void o开发者_高级运维nClick(View v) {
        //do some work
    }
});

for my Button. the application works fine once I use only on listner!!!!

please help,thanx


try this

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

value.setOnItemSelectedListener(this);
}

    @Override
    public void onItemSelected(AdapterView<?> parentview, View V, int pos,
            long arg3) {
                                  }


I think you are initialized the any view on activity ,firstly initialized the all component which you are using in xml

use this line for button in activity

mButton=(Button)findViewById(R.id.button);

then it would be work.

0

精彩评论

暂无评论...
验证码 换一张
取 消