changing visibility of text android - android

Hi i have two textViews that i initially set its visibility to gone then animate in and become visible. now i want to make the invisible again but for some reason they're still showing on screen does anyone no why?
in my onCreate() i make the view gone
register = (TextView)findViewById(R.id.register);
register.setVisibility(View.GONE);
forgotpassword = (TextView)findViewById(R.id.forgotpw);
forgotpassword.setVisibility(View.GONE);
then later on i make it visible
public void run()
{
animations();
loginForm.setVisibility(View.VISIBLE);
register.setVisibility(View.VISIBLE);
forgotpassword.setVisibility(View.VISIBLE);
}
and then when a user presses a button i want the text views to become invisible so that they retain their layout but they stay visible on screen
signInBtn = (Button) findViewById(R.id.signin);
signInBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
signInProcess();
}
});
public void signInProcess() {
register.setVisibility(View.INVISIBLE);
forgotpassword.setVisibility(View.INVISIBLE);
setuploader.setVisibility(View.VISIBLE);
}

In Android when you animate something, It's just drawn somewhere else. The actual element is not moved. So when you animate signInBtn it's drawn somewhere else, but the actual button is not moved from the original position. So when you click the button the click handler is not called.
To avoid this set fillAfter = True in your animation so the button will actually get moved at the end of your animation.
Also, after animating a view in Android make sure you call View.clearAnimation() before trying to change its visibility.

Related

ScrollView not scrolling to end while adding a new view android

I have a scrollView in which while I am at end of the scrollView, on clicking a button at the end I need to show a view below that button. I am doing it by changing the visibility of that newly added view from GONE to VISIBLE. Its working but after clicking the button I am not able to see the newly added view i.e I need to scroll down the scrollView to show that view. Is there a way to scroll the ScrollView to that newly added view after clicking the button? and also to hide that view and scroll back to normal state after clicking that button again.
Thanks in advance!
it's an alternative which pretty much does the same thing.
Instead of Scrolling to the bottom of the screen, change the focus to a view which is located at the bottom of the screen.
That is, Replace:
scroll.scrollTo(0, scroll.getBottom());
with:
Footer.requestFocus();
Make sure you specify that the view, say 'Footer' is focusable.
android:focusable="true"
android:focusableInTouchMode="true"
or if above is not working try this
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
As the view that i was adding at the end was added with an expand animation so i used a countdown timer for it as follows:
new CountDownTimer(500, 1) {
public void onTick(long millisUntilFinished) {
myScrollView.scrollTo(0, R.id.bottomView);
}
public void onFinish() {
}
}.start();
Thats all.

How to scroll a few pixels down programatically Android Studio

I made a Ctrl+F search box with next ocurrence button, when i click next it scroll to next word, but the word is out of screen , if i scroll a few pixels down , you are able to see it.
so after the method find next is called i would like to scroll a little more so the highlighted word is visible.
mFindNextButton = (ImageButton) findViewById(R.id.find_next);
mFindNextButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mCurrentWebView.findNext(true);
//scroll a little more()
}
});
Maybe something like this:
scrollView.scrollTo(0, scrollView.getScrollY()+10); // Scroll down 10 more pixels

Android Layout button partially appears

So,
I have an activity with a layout, and in this layout I only have one button.
when clicking this button, the activity sets the visibility of the button to invisible, and launches a popup window.
I implemented a simple onDismiss function in this popup, which sets the button to visible
pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
MainActivity.packButton.setVisibility(View.VISIBLE);
}
});
the problem is that sometimes, not very often, after the popup is dismissed, the button is shown, but only the top part of it, something like 1/5 of the button.
I suspected that the button became visible before the popup dismissed completely, and a sort of a clash happened between them, but on the other hand I made some checks and the popup window and the button are able to be shown at the same time without a problem, so a "layout clash" cannot be the reaon, right?
You can add delay and run this method on a handler.
pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
MainActivity.packButton.setVisibility(View.VISIBLE);
}
}, 1000);
};
});
I would suggest making the button variable non static and instead call a method of your activity from your listener and in this method set the button visibility. Having the button as a static variable could mean that although it is non null the button isn't added to the activities view at the point when you call to set is visibility.

Button wont become invisible after being clicked - Android

I have a button that is set to VISIBLE under certain circumstances, then once its clicked its suppose to make the button INVISIBLE again but for some reason its not working. Here is my code,
if(variable == 2){
testButton.setVisibility(View.VISIBLE);
testButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
testButton.setVisibility(View.INVISIBLE);
test2Button.setVisibility(View.VISIBLE);
}
});
}
Have you tried displaying a toast when the button is clicked, just to see if that block of code is even executing? I don't see it, but I'm assuming you've actually declared a View associated with that button via 'findViewById'
EDIT:1
Do this
public void onClick(View view) {
view.setVisibility(View.INVISIBLE);
findViewById(R.id.<your test2Buttons ID>).setVisibility(View.VISIBLE);
}
Note: If you do View.GONE it will leave all area acquired by it and the other control will capture this area
where is with View.INVISIBLE it will maintain its acquired area

Android: enable temporary touch/click for all views but one

I have a set of buttons and views displayed on the screen. At some point, I would like to be able to interact only with one of them and block all the others.
And I need to retain all the listeners to restore theirs behaviors later.
Any ideas?
Thanks!
For disabling buttons, when you clicking on a specific button/view, disable other buttons/views in the specific onClickListener like
//button1 onClickListener
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
button2.setClickable(false); //disable button2
view1.setClickable(false); //disable view1
}
});
likewise for all other buttons and views, then you may enable those by calling
button2.setClickable(true);
view1.setClickable(true);

Categories

Resources