android set a view to invisible and back to visible - android

I have a FrameLayout I want to disappear it on a button click and make it reappear on a button click
I tried this to disappear and it worked great
background.setVisibility(View.INVISIBLE);
background.invalidate();
but when I tried to get it back using the below code it didn't work.
background.setVisibility(View.VISIBLE);
background.invalidate();
What is the right way to do this?

check the thread on which you are executing these

just have a look at this example. This may help you!
And I think the method invalidate() invalidates the view (after invisible the view)and so it's not reverting back(invisible to visible).

Related

ShowCaseView does not hide when touching outside

new ShowcaseView.Builder(mainTabActivity)
.withHoloShowcase()
.setTarget(new ViewTarget(recyclerView.findViewHolderForAdapterPosition(0).itemView))
.setContentTitle(getString(R.string.tutorial_welcome))
.setContentText(getString(R.string.tutorial_cardview_add))
.hideOnTouchOutside()
.build();
This is my code when attaching the showcaseview onto the recyclerview first item. It works although the animation seems to be laggy I don't know why, and also the problem is when I touch outside or press the "ok" button. The showcaseview does not hide instead I have to press the "ok" or touchoutside for a few times "four times" I think, to make it go away completely. Am I missing something?
I am using this https://github.com/amlcurran/ShowcaseView library.
I have tried giving it an onClickListener and calling removeAllViews() but it's crashing the app.
I found a solution, what I did was to directly initiate the whole thing in the adapter of the recyclerview and hold it in a condition that would prevent it from popping up more than once.

setEnabled(false) not hiding TextView

So I'm following an Android tutorial and came across an issue. The video maker uses setEnabled(false) to hide a TextView until the user clicks a certain button. However, when I tried the same code, the TextView was on the screen before the user clicked the button. I've been trying to work out why for an hour, but to no avail. Below is a link to the video and a picture of my relevant code, XML code, and screen display.
Video: https://www.youtube.com/watch?v=NGRV2qY9ZiU Talks about setEnabled at 16:35
However, when I tried the same code, the TextView was on the screen before the user clicked the button.
setEnabled(false) won't actually hide the TextView. To do that you need to do
result.setVisibility(View.GONE);
When you are ready to make it visible (instead of setEnabled(true)):
result.setVisibility(View.VISIBLE);
try
result.setVisibility(View.GONE);
instead.
Edit:
note that:
result.setVisibility(View.INVISIBLE);
would also hide the view but it would still be clickable.
Use the below method. It will hide the element from the view.
result.setVisibility(View.GONE);

Manually Show ExpandableListView

How to show ExpandableListView manually if i touch a button. So far, the only way i can open it is by sliding the screen.
I couldn't find any method like show() like on Toast. I've tried looking for any similar sound method on android reference.
I think you can try scrollTo method to scroll to a postion.
For open/ close a group, you can use expand method.
I found the answer. Turns out, i was wrong. I should've animate the container. In this case, the drawer.
I got my answer from here. How to open Drawer Layout only with button?
I just need to call opendrawer().

setVisibility with sleep

I have this code:
result.setVisibility(0);
//a lot of code
//OnClick......
result.setVisibility(8);
SystemClock.sleep(500);
result.setVisibility(0);
So when i click a button the textView disappears and reappears to show that the result is changed.
But instead the textView "result" don't disappear and remains always visible. Why ?
I am not sure if the setVisibility function is at fault here. It appears that you are trying to sleep inside the UI code which happens to be a very commonplace mistake.
I am not sure but this willl help you.
Also I would recommend the usage of the pre defined constants VISIBLE , INVISIBLE and GONE instead of the integers.
Good Luck
Because you tell the thread that need to update the ui to go to sleep...
You should use animations for this stuff.

Menu does not showup first time after install

i a facing very weird problem in my app. i am inflating a layout on pressing menu key. and setting that layout on popupwindow. the prob i am facing is that when i install build on device and press menu key, popup does not show up. but if i navigate to some other screen and come back to previous screen, menu key works perfectly.
even if i cllose app and open it next time, menu key works fine. it does not work for the first time after install.
thanks in advance.
Maybe you set your click listener for the menu button in the wrong lifecycle method? Perhaps it doesn't add the listener until after onPause()? Seeing some source would be very helpful to be sure.
I think android pretty much decides on its own when it updates its layouts and redraws the view. Maybe your newly inflated view doesnt affect the other layouts in a way that makes this seem neccessary. I would try to call requestLayout()/forceLayout() on the main layout...
Not sure though...

Categories

Resources