How to set button invisible android
11,692
Solution 1
buttonName.setVisibility(View.GONE);
This is better than (View.INVISIBLE) cause the button doesn't get any space from the layout. If you want to make the button another time visible just use:
buttonName.setVisibility(View.VISIBLE);
Solution 2
try to do like this
button1.setVisibility(Button.INVISIBLE);
Solution 3
The code you written for making button invisible is correct. Check whether the variable level is 1 or not.
Author by
stevedc
Updated on June 04, 2022Comments
-
stevedc about 2 years
So I tried to make A button invisible, I searched first the forum for the answer and tryed it but it just doesn't work.
int level=0; try{ String FILENAME = "TowerFile"; FileInputStream fos = openFileInput(FILENAME); byte[] b = new byte[1]; fos.read(b); fos.close(); if(new String(b).equalsIgnoreCase("1")){ level=1; } if(new String(b).equalsIgnoreCase("2")){ level=2; } if(new String(b).equalsIgnoreCase("3")){ level=3; } if(new String(b).equalsIgnoreCase("4")){ level=4; } if(new String(b).equalsIgnoreCase("5")){ level=5; } }catch (java.io.FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); } Button button1 = (Button) findViewById(R.id.button1); Button button2 = (Button) findViewById(R.id.button2); Button button3 = (Button) findViewById(R.id.button3); Button button4 = (Button) findViewById(R.id.button4); Button button5 = (Button) findViewById(R.id.button5); if(level==1){ button1.setVisibility(View.INVISIBLE); }
So I first get A variabel out of my file, and then I want to make A button invisable depending on the output. I get the wright number out of my file but it doesn't do anything, I also did 0 and gone but nothing works
-
Shankar Agarwal about 12 yearscan you paste your xml file too
-
-
vipin about 12 yearstry that code without if block if and let me know what happen
-
stevedc about 12 yearsYes without the if statement it doesn't appear
-
vipin about 12 yearsoh it shows there is problem in you logic that level is not get assigned by the correct value please check your code new String(b).equalsIgnoreCase("1") assigning level or not
-
stevedc about 12 yearsYes I found it to but I am using the same method for my languege and that works
-
vipin about 12 yearsmeans your proble get resolved or not if resolved then set type of question close
-
vipin about 12 yearsor is there any other issue raised