Spinner in Android crashing when visibilty changes while handling OnClick in a button
- by Dave George
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.
}