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);
Related
In my application, I want to provide the functionality similar to Next, Previous and Done button at the top of keyboard. It is somewhat similar to this
Please let me know how can I achieve this.
I do not want to exactly implement the next,previous and done options. But using this three button click, I want to make three separate web service calls and fetch the results. Like, Active,Inactive and All kind of filters.
The standard Android way would be to provide an input method action with imeOptions. With the standard keyboard this will change the bottom right virtual keyboard button to the specified action. There's little point in trying to mimic iOS input behavior with the buttons above.
Do you want to just put the layout above the keyboard,so as to stop next,previous,etc button when keyboard is displayed.
If so,you can try adding below code inside your activity in android manifest,
android:windowSoftInputMode="adjustResize"
If you are looking for something else,then please show your xml code of the same.
I want to set a button to be invisible because there will be a picture in front of it to act like the button. Do you guys know how to set this up in the xml?
thanks in advance.
Maybe the best thing you can do is to use directly an ImageView instead of a Button, setting always a OnClickListener on it in order to catch click action. Maybe you can also add a proper selector in order to get a visual feedback on the pressed/unpressed state.
I've got an EditText, which is ultimately inside of a ScrollView. I've implemented a comment feature which takes you to a new activity, and automatically places focus in the edit text so that the user can immediately start writing his comment.
Unfortunately, it doesn't quite scroll the edittext into view, as you can see in the screenshot below:
I would like to see something more like this, where the EditText comes completely into view (see below). I already looked at the android:WindowSoftInputMode, and it seems like the default values should work ... and indeed, it does mostly work because it does scroll, just not enough.
So is there anything I can do to get the desired behavior? Thanks!
is your min SDK 3?
check this
Hope you have tried android:windowSoftInputMode="adjustPan" and check this.
I would give this a go.
You could also try to programatically use this on the onCreate() method of you activity.
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
"SOFT_INPUT_ADJUST_PAN" adjustment option is set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible.
I have a button that plays a sound clip when it is pressed. I would like the button to appear pressed during the duration of the sound clip. By that, I mean that I would like the button to take on the default pressed-button appearance while the sound is playing. How can I implement this? I have tried using a number of things in the onClickListener (such as setSelected, requestFocus, etc), but none of those do the trick. I have also tried changing the onClickListener to an onTouchListener, again with no dice. Am I wrong in assuming that there must be a way to simply set the button image to appear pressed? (BTW, the button object is of type Button, not ImageButton).
Thanks for any advice!
Please see this question. It details a couple of different ways this can be done.
Lookup 'selector' drawables and let android take care of this for you.
I have an app widget which runs neatly. However, I am unable to highlight a click on a linked item. I've seen it in the standard app widgets like 'Music' and 'Power Control', for instance. Moreover, I've also been studying the Music app widget's source at album_appwidget.xml. The only thing I could think of is the LinearLayout defined at lines 23-35 which states
android:clickable="true"
Unfortunately, this does not work for me. So does anyone have a hint on how to highlight a click on an app widget? I've tried the LinearLayout, TextView and Button. None of them displayed a border as a highlight.
Thanks in advance,
Steff
you need to create images for those states like focussed state, pressed etc like in a button and define them in your background.
Try looking at the custom buttons where its explained how to accomplish the task thats similar to your needs.
http://www.gersic.com/blog.php?id=56.
if you want to look more and add more states you may ge better idea if you look at the android source code for buttons where they have images for each state of the button and every other widget.