I have set the visibilty for button as "gone" but now when i want to set button visible , Getting following error while trying to set visibility for button
@Bind(R.id.btn1)
Button btn1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.hifragment_main, container, false);
if(1==1)
{
btn1.setVisibility(View.VISIBLE);
}
return view;
}
you didn't initialize you button, please initialize it as below,
View view = inflater.inflate(R.layout.hifragment_main, container, false);
btn1 = (Button) view.findViewById(R.id.btn1);
You need to initialize your button object.
btn1 = (Button) findViewById(R.id.your_btn_id);
Then you can check if (btn1 != null)
for example if you are in mainActivity : in onCreate method:
if you don't use setcontentView
here, it will give you nullException
setContentView(R.layout.activity_main);
and then
btn =findViewById(R.id.btn); btn.setVisibility(View.VISIBLE);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.