I have created a progress bar in Android Studio that goes from 100 to 0 with a step 10 and sleep(500).Each step is displayed.
Now what I want to do is to make the step occur whenever I click on the bar.
How do I do this?
I wouldn't like to create a button on the backgroud of the progress bar, I would like to be able to click on it and make it wait for my next click.
Thank you!
I think you can set
android:clickable(true)
android:onClick(something())
when you set onClick, you dont need to set a ClickListener
Related
There is a button and when it is clicked on I want a message to slide to right and then fade away. It works only the first time this certain layout is loaded. This is what I've written
popTextView.animate().translationX(popTextView.getWidth()).alpha(0.0f).setDuration(1500);
Set repeat rount for your animation.
animation.setRepeatCount(Animation.INFINITE);
or
animation.setRepeatCount(5);
try calling YourView.getAnimation().start(); while clicking on button
I am trying to implement a simple logic in my application where the user is shown a popup (after sometime of application launch). The popup simply shows a TextView with some info message. This message is refreshed every time the application is launched and a new message is shown.
The UI of the popup matches my application UI - here maybe just popup background images is needed. Also one close button (X) is shown at the top right corner of the popup - to close this popup.
Logic of Showing Message: I have a String array having some 100 strings stored in it. I randomly pick one string from this array and populate the popup TextView showing the message. Please suggest if there is any better approach than what I am doing already here. Also is it possible to logic that if one message is picked then the same message is not picked until the other messages are shown at least once?
Logic of Showing Popup: This is what I am not able to implement. I do not want to anchor the popup with any user Event or Button click. I simply wants to show the message after some time - say
Thread.sleep(3000);
Now I have tried to use PopupWindow for this using the below code.
PopupWindow infoPopup;
LinearLayout infoLayout;
TextView infoTextView;
Button infoButton;
infoTextView = new TextView(this);
infoTextView.setText("Testing Popup Text");
infoTextView.setPadding(10,10,10,10);
infoButton = new Button(this);
infoButton.setText("Close");
infoLayout = new LinearLayout(this);
infoLayout.setOrientation(LinearLayout.VERTICAL);
infoLayout.addView(infoTextView);
infoLayout.addView(infoButton);
infoPopup = new PopupWindow(infoLayout,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
infoPopup.setContentView(infoLayout);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
infoPopup.showAtLocation((CoordinatorLayout)findViewById(R.id.main_content),Gravity.CENTER,100,100);
But this popup is showing error at the last line giving null pointer on my
(CoordinatorLayout)findViewById(R.id.main_content)
parameter.
The issue that I am getting are:
First of all, I am not sure if this is the right approach of showing a custom UI popup. I am aware of AlertDialog but not sure which is the best option to go in this case - Please suggest.
Why the CoordinatorLayout is showing null pointer?
How to implement the top right (X) button logic in this Popup ?
1. Yes there are so many options for showing a custom UI popup in Android. You might select one from PopupWindow, AlertDialog or Dialog Activity. You need to decide which suits you best.
If you need to customize your UI a lot and have to show a list or some complex GUI then I would suggest you launch an Activity with theme.Dialog. Just set the theme of the Activity to something like this android:theme="#android:style/Theme.Holo.Light.Dialog". There's a plenty of tutorials for implementing a dialog Activity.
PopupWindow is another tool to customize your custom pop up anywhere in the screen. If you're showing this popup always in the middle of the screen, then I would like to suggest not to use this. The AlertDialog should work fine.
AlertDialog has many variants and as far as I can assume your problem, this one suits you best. You can have a cross button too in the top-right corner of the dialog (You can set the icons anywhere, as you can provide a custom layout to an AlertDialog). Personally I use this library to provide a custom layout to my AlertDialog. You can have a look at this too.
2. The NullPointerException is simple. Your layout doesn't have any id named main_content. Post your logcat if this doesn't solve your problem. Post the layout too.
3. As I've told you earlier, I use the library to provide a custom layout to an AlertDialog and you can have a look at it too. So after implementing this library you can easily design your own layout with a cross button and implement the onClick functionalities easily.
Hope this helps.
Activity with theme Dialog.
This is not a good idea. It looks like a pop-up, but you can't click outside the pop-up to close it.
PopupWindow
It will stop the application. When the user finish clicking the pop-up, the application can work again.
AlertDialog
The best one, it will not stop the application and can be closed by clicking outside the dialog.
I'm trying to add 1, 2, 3 or 4 images in 1 button.
This is what I want to get but I only get 1 image in my button.
Does somebody know a solution for this.
I us setIcon to add an image in my button.
Why do you need to have this be a button object?
I would make a custom view that emulates the button behavior, but is actually just a View with 2 images behind it. You can set an onclick in XML or in Java for that Activity, different styles for normal and pressed state in XML
I have to make a project for school and it has to look like the game puralax. every white circle is a move. So with this button you can move 2 times. so that's the reason of my question. Also when you move the button, 1 circle has to disappear.
I am writing a selenium test for the following flow:
Select all items.
Click on the Run button - opens a pop-up with two buttons "Proceed" and "Cancel".
Click on "Proceed", opens the new pop-up which will display the progress bar.
Here are two problems I am facing:
I am able to click the "Proceed" button via selenium code, but the moment it gets clicked the other pop-up which displays the progress bar doesn't show up, because of thisthe selenium is not able to identify the element. How can I handle this?
The Progress bar has one button "Cancel", while the progress bar is being filled the Value of the button remains "Cancel", but after it reaches 100% the Value changes to "Close". How should I handle this?
I tried the following, but it didn't work:
Tried to wait until the visibiltyOfElement, presenceOfElement of the element (progress bar) by XPath and id.
Tried Thread.currentThread.sleep after clicking "Proceed" and Implicit wait too.
Tried to wait until AlertIsPresent.
The code:
// Select all items
wd.findElement(By.id("ListSelectAll")).click();
// click on Add the selected
wd.findElement(By.xpath("//*#id='ListRunLink']/img")).click();
// Proceed to confirm Adding
wd.findElement(By.xpath(".//*#id='Proceed']")).click();
// Wait until the Progress Bar Gets Displayed using the buttons
// present in the Progress bar to address Wait!!
wt.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[#id='Close']")));
// The above code does NOT work - "not able to locate element with id CLOSE"
Can someone help me with this?
This is my first question at stackoverflow :-). However, I've started to Android programming some weeks ago and now I have get into a problem that I will describe below.
Problem:
I have a background-image for the whole screen. Inside this LinearLayout I have another LinearLayout with Buttons inside. How can I (without to start a new activity) load another buttons and make the first buttons disappear. The Buttons have a drawable background-image assigned to the specific button.
Like: I have a menu; play, options and quit. When I for example click on Options, the Options should load, and the play-button, options-button and quit-button should disappear.
All I want to become is to remain the background-image without to create a new activity and always can load a bunch of new buttons depending on the button that was clicked on.
For now I have created a new activity for the new buttons that should appear for example: Exit -> Do you want to Exit? Yes or no., then I also have done so the new acitivty loads another xml-layout-resource file, with the same background as before. This is what I want to change to a smoother resolution.
Make two buttons with your second layout. use button1.setVisibility(View.GONE) method to set the visibility of the button. check this link