Android Studio viewFlipper Crashing App - java

I'm making an application. I have succeeded in creating a viewFlipper with:
android:flipInterval="5000"
android:autoStart="true"
I've also made two buttons, next and previous, with:
android:clickable="true"
android:onClick="onClick"
I want each button to affect the ViewFlipper, as in when the next button is pressed, the next image is displayed. And, when the previous button is pressed, the previous image is displayed.
What do I need to add to the XML file and what do I need to add to the MainActivity class? Everything I've tried up until now either prevents the app opening or crashes the app when the button is pressed.
Any and all help is greatly appreciated.

Related

How to turn it off the snap button and ok button in camera by android studio?

I currently require to design a camera function for android version 4 (Kitkat), but i notice that there is snap picture button and ok button in the camera as picture below:
How to make it disappear and user just touch on screen it can snap the picture without the button, and the picture will directly save without need of pressing ok button.
Anyone can share me the ideas, I very need you guys help because suffer this for long time already, thanks.

Issue with android studio and radiogroup

I'm trying to make a simple app in android studio but running into trouble with layout whenever I place down a RadioGroup. In my first image here I've created a RadioGroupand dragged two RadioButtons into it by dragging them to the radiogroup option on the component tree trying to drop them into the radiogroup on the layout thing is impossible as the radiogroup is completely invisible on it.
I drag a button below it, lining it up with the center, and the box that shows where the buttons going to go shows it being below the radiogroup. But once I release the mouse button, the button im attempting to place ends up here.
I've been fighting with android studio for a while now but if I get the button even remotely close to the RadioGroup it gets catapulted up the screen, and I don't have enough room if I place the button way down low for my other elements.
tl;dr
radiogroups are catapulting any elements underneath them above them. its probably a layout or gravity issue or something like that. but I don't know how to fix it and would like my buttons to not be underneath all the other elements kthx.
I'm not sure what is causing your issue, because you aren't providing enough information. But If you want the button to appear under your radio group, then in your xml file, give your radio group an id android:id="#+id/radioGroup" and in your button add android:layout_below="#id/radioGroup".
Try to android:layout_below="#+id/radioGroup" in your button.As your are using Relative Layout by default it takes you top while dragging.Here is full Button view.
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:id="#+id/button"
android:layout_below="#+id/yourRadioGroupId"
android:layout_centerHorizontal="true" />

how to give an event to the entire screen with so many button and other layout? android studio

i have a project that is calculator, there is many button and layout above the main layout, i have a history frame that hidden at the right screen, i want that if i swipe the edge of the whole screen and ignore the button and other objects there, the history frame shown
i already read the question here
how to fire an event when someone clicks anywhere on the screen in an android app?
but it didnt work for me
thanks
I solved this problem using dispatchTouchEvent.

Android Button background Image changes back to state in XML

I have a simple soundboard which uses Buttons to represent the sounds. When a sound button is clicked. The background image is changed using the view.
Button butt = (Button)view;
butt.setBackgroundResource(buttons_on[media]);
buttons_on is a int[] representing the drawables of the buttons.
This all works perfect, but I also use a FragmentActivity to create a paged App. The App has 4 different pages which you can swipe through. When I change a button using the above code and swipe two pages to the right and than swipe back. The image of the button has changed back to it's default defined in the page.xml.
How can I prevent this behavior?
change the Buttons to ImageButtons and setting the src?
somehow prevent the page from reloading
Instead of doing that you should look at how to use a StateListDrawable. It will simplify your approach.

Impossible to update the text of a textview in a RelativeLayout

I have a simple screen created in xml, the parent layout is a "relativelayout" and i have a child layout (who is also a "RelativeLayout" containing 3 textview inside).
the only thing I have to do is press a button and change the values ​​of textviews.
to change the text is obviously this:
MyTextView.SetText("Text");
the code runs perfectly, but does not refresh the text of the textviews in the layout.
but when the screen is rotated, the screen refreshes, and the label gets the correct value.
Why does this happen? Why when pressing the button I can not update the text?
I tried using "AsyncTask" and the text is not updated either.
Did something simple can be so problematic. ?
greetings.
Your code
MyTextView.SetText("Text");
Should be executed on UI thread to give effect say suppose if you want it to be updated after button click then this code should be inside your onClickButton listener of your button
Visit This Link for more details

Categories