I have defined my Relative Layout using the drag and drop tool in Eclipse, so all of my buttons are laid out how I wish. My issue is when I set the onClick listener, that calls a method in another class. So to be able to redraw items on screen, I need to access the layout manager so I can add and remove buttons from the screen as well as update textViews. I have done all of this in a demo I made in Java, and I used a JPanel with GridBagConstraints. Now that I am moving to Android, a system I haven't done much development in, I am at the point where I have to learn some new stuff. For example in my demo I made I could do this:
grid.remove(trueButton);
grid.add(falseButton);
grid.remove(textField);
grid.add(backButton);
Essentially I want to be able to do the same sort of thing in my Android app. If you guys need more info I can provide, I wasn't really sure how much would be needed since I am looking at really just where to start. Everything has been declared in the XML since the drag and drop part of Eclipse does that all for me. It is just the Java part that is giving me some issue.
Why not just setVisibility of the buttons you wish to hide/show? Same with the TextViews.
You can set visibility to 'GONE' and it will be as if the view has been removed (taking up no space in the layout and not responding to touch events.).
Related
I'm relatively new to coding, especially with android(xml,java).
I had an idea for an app but it appears that it requires a layout that I can't seem to find.
So what I'd need is a layout that starts out with the screen size and dynamically expands in the given direction as the user drags along the screen.
In addition to that I want to be able to create objects(textview, imageview) at any given point on the layout which can also overlap as they can in Absolute- or RelativeLayout. Those objects should dynamically be loaded and destroyed as they move in and out of view.
So I don't know if there's anything like this. I've searched for quite a bit but only found layouts that were able to either scroll horizontally or vertically.
If anybody got an idea how I could possibly realize such a view, please let me know!
Best regards, BlackCert
In your case, doing everything manually through OpenGL seems appropriate. You could render only the items that are visible and dont have to mess with Android getting painfully slow when dealing with huge layouts. Set-Up a 2D scene and write rendering code for each kind of item you want to display.
So to expand on the question stated, to my best understanding android apps have a set of activities such as the default activity_main.xml and you could even generate a login screen (activity_login.xml). After fiddling around with it I sort of feel comfortable with the way buttons work, yadda yadda, but my problem emerges when I want to create a game activity. I am not concerned about that part, I would just make another activity (activity_gameplay.xml) that I would run the game on. My problem is that I want to render my own custom buttons onto the screen which would be transparent and would be stationary while the actual game environment would be moving. Such as in Minecraft(android version obviously).
So to conclude I need to know how to render custom buttons, and though not included in the above, how to position the buttons accordingly sense the XML way only allows stuff such as upper left-hand corner etc.
I have a general question that is Java related.
I am writing an application that has a GUI menu. I am trying to change one part of the GUI menu based on the selection of a Radio button.
Do I need to:
Redraw the whole window or just update that part with:
setVisible(true)?
If I just use the statement from #1 above .. the GUI is fine -- until I move the mouse over it and then I see the previous button choice. What am I doing wrong?
Swing components have a repaint(), revalidate(), and doLayout() method. One of those should probably be able to redraw whichever pieces you want. However, doLayout is not something that you should be taking responsibility for, that's the layout engines responsibility.
You may also want to check out this post, the first response has a pretty good explanation, and links to an article with more detail.
In terms of the second part of your question, I'm not sure, but we may need to see some code to get an idea. Is the 'replaced area' actually being removed from the view?
..in my application the user select which device platform type they want top test (that choice is a set of two radio buttons on the left). When the user selects either Android or iOS, the center grouping of check boxes changes to reflect a group of android devices they can test or a group of iOS devices that they can test.
Put a panel in the 'center grouping'.
Use a CardLayout for the panel.
Add both iOS & Android controls to the panel with the card layout.
Flip between them as needed.
Call revalidate() on the top level component.
I'm currently making an android app in which I'd like the user to be able to change the background image.
I've got 3 images and a screen where I can choose a picture and a button for applying.
The issue:
I can allow the user to see all images in the way I want, but I don't know how to set the selected image as app background.
What I want to do:
I want the user to click a button, which exports the selected image to "bakgrund.png" in "/res/drawable-mdpi" and replaces the current one. This would allow me to easily integrate the background switcher. Renaming of current files also works.
PS: My current background images are located in /res/drawable-mdpi named 1.png 2.png and 3.png.
Easiest way would be to call the setBackgroundResource(image_id) method on the root layout. Like if you have a LinearLayout which has android:id="#+linear" as the root layout in the layout xml, then this code will help:-
LinearLayout linearLayout=(LinearLayout) findViewById(R.id.linear);
linear.setBackgroundResource(R.drawable.1);//call this in the OnClickListener's OnClick Method
Firstly, you need different themes which has different backgrounds. So you may use this.setTheme method in your Activity.
Indeed I suggest you, two different layout (with different backgrounds but have same components) and using setContentView during onClick.
I hope it solves your issue.
I am working on an Android project where a group of buttons needs to show on the bottom of every screen (activity) in the application. The group of buttons are basically a navigation bar. I want to know the best way to do this without creating new buttons for every activity. I have been around programming (C++/C#) for many years but am pretty new to Android and Java so if someone can point me in a general direction, it would be appreciated.
Thanks.
I bet you need to use "include" tag for xml layouts. It's the best when you need to reuse some UI components. See http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/ for the examples and description.
To elaborate on Konstantin's answer, after you've used include, you'll need to bind actions to these buttons.
If the buttons should have the same action regardless of the activity they are in, use the include tag to create their layout and then create a parent NavigationActivity (or whatever else you want to call it) class from which all your other activites will inherits.
In the parent NavigationActivity class' onCreate method, you can set up the onClickListener (and other needed stuff) for the buttons.