I am trying to hide a view/layout when one of the menu items is clicked but i keep getting a nullpointerexception.
This is how i am doing it.
RelativeLayout relativeLayout;
relativeLayout = (RelativeLayout) findViewById(R.id.layouttohide);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_cog:
if (relativeLayout.isShown() == true) {
relativeLayout.setVisibility(relativeLayout.GONE);
}else {
relativeLayout.setVisibility(relativeLayout.VISIBLE);
}
return true;
case R.id.action_stuff:
Toast.makeText(getApplicationContext(),
item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
In the XML file this is how i have the layout setup.
<RelativeLayout
android:id="@+id/layouttohide"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="0dp"
android:background="#025fb6"
android:visibility="visible" >
No comments:
Post a Comment