Spinner in Android crashing when visibilty changes while handling OnClick in a button
Posted
by
Dave George
on Stack Overflow
See other posts from Stack Overflow
or by Dave George
Published on 2012-04-09T05:03:39Z
Indexed on
2012/04/09
5:29 UTC
Read the original article
Hit count: 444
I have a spinner in UI, which I want to hide when I handle onClick
method for a button. But the application is crashing all the time. Is it that I can't use the setVisibility(View.Gone)
on spinners (it is not written anywhere). If I comment it out, then application run fine. I am getting NullPointerException
and I am using RelativeLayout
. Also, can I do this:
public void onItemSelected(AdapterView<?> arg0, View view, int pos,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(SpinnerActivity.this,selected , Toast.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
}
}
Spinner code fore reference:
itemsCity=getResources().getStringArray(R.array.cities_array);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.cities_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCity.setAdapter(adapter);
And here is Button code:
private class BtClickListner implements View.OnClickListener{
@Override
public void onClick(View v) {
essEditText.setVisibility(View.GONE);
spinnerCity.setEnabled(false);// Getting exception here
// Also tried
spinnerCity.setVisibility(View.GONE);// Exception
SameBt.setVisibility(View.GONE);// This is same button for which I am handliing event, but it allows me to change tis property at run time.
}
© Stack Overflow or respective owner