Runtime button creation in Android studio? - android

This isn't so much a question about my specific code as it is a question on what I need to use to accomplish my task.
I'm making a workout logging app for my class. The user needs to be able to create a workout routine, filled with various exercises of their choice.
On the home page, there is an "Add Workout" button. Clicking this should bring them to a screen where they name the workout and fill it in with said exercises. When they click save, I need to be able to create a new button on the home page with simply the name of their new workout. This new button when clicked will bring them to that workout, where they can start the workout and put in their reps, sets, weight, etc.
What do I need to be looking at to achieve this? Do I need to be saving the workouts to a database and using a function to go through the database and populate the home screen with respective buttons each time I enter the app / add a new workout? Or is there a different way to do this? I'm not sure that I'm even asking the right question or framing this problem the correct way.
Thanks!

you should put the button on the home page from the beginning but make it invisible at first.
yes you should put the workout information in a database and if there is a workout saved, make the button visible in the home page.
use android:visibility="gone" in XML and birthday.visibility = View.VISIBLE in the activity to modify the visibility

Related

Clicking a button to open new activity showing data from firebase

I'm very new to coding so please excuse my lack of knowledge.
I have managed to set up a button which opens a new activity in my Kotlin android project. I want to be able to display the data from my firebase batabase in the new activity when the button is clicked but have no idea how to go about it.
For example, I have 3 buttons for 3 places. Each button opens the same activity which should display the data corresponding to that place in certain textviews (name, addess, etc)
What would be the best way to go about this?
Thanks in advance.

Android make a edit info fragment

I'm making an Android app. I have to make a fragment where (for example) the user can see his info, like his name, email, birthdate, etc. I want to allow the user to edit this info, but i don't know which approach is better. I thought to put all the infos in some editTexts with setEditable = false and make a button EDIT that when the user click on it I set the visibility of this button to GONE and make the visibility of the hidden button UPDATE to VISIBLE and the editTexts to setEditable = true. When the user click on UPDATE if is all correct i send the updated infos to the backend and I set again the visibility of UPDATE button to GONE and the visibility of button EDIT to VISIBLE and all the editTexts to setEditable = false.
Is it a good solution or i can do it better?
Your best approach would be to to display user profile in the fragment and then provide a button for the user to click on to Edit. On button click you can launch a new activity to allow editing - this is the approach i generally use. It is less complicated in the beginning. On the other hand, it would be nice to implement both and then use A/B testing to figure out what works best for your users, in your context. This is more a UI/UX issue rather than a programming one... all the best.

Android - Loading data from next screen when going back to previous screen

I am building an application that has a screen that needs to be filled with data. At some point there's a button called "Add Category" which will redirect the app to another screen where the users will be able to add some custom categories and after selecting all the ones they will click on "save" and be redirected to the previous screen. The thing is that I want the screen to still have the data inserted previously and, mainly, the new categories that were just added.
I would like to ask you all what is the best way to do that? I want to have an general idea about the structure of the activities how can I do that and the things I would have to use. I know that when I go back without finishing an activity I will still have the fields filled, my main concern is about getting what was inserted.
If I use intent when he user presses the back button the data will be passed but how can I make the previous screen receive them without losing what was inserted previously?

maintaining view state android

Please don't delete it because its a duplicate. I am an android developer with little experience. I have an app with 2 screens. The first has a bunch of options in a TableLayout each selected using a RadioButton.
What I want to do is, when I select one option and click a Button which appears below, the View should switch to the next screen showing some related data and when a Button is clicked I want it to come back to the same screen but then the rest of the options should be available to me so as to repeat the same process with another one of the options selected.
In short I want to be able to maintain the state of the first screen. I can't seem to be able to decide between using ViewSwitcher, ViewFlipper, or multiple Activities or using a single Activity which is what I am doing right now. But as my app gets bigger its very difficult to handle it. Please suggest the best way to do this. I am confused and desperately in need of help because my job depends on it. Thanks in advance
Use 2 activities. Launch the 2nd activity when the user clicks the button. When the user clicks the "back" button (or some other button you offer him) the 2nd activity finishes and the first activity (which was underneath it) is shown.
Note: You've not given us much information, so I can't guarantee that this is the best solution. From what you've said this is the solution I would recommend though. As they say in advertising "Your mileage may vary" ;-)

Component to add arbitrary number of input fields?

I apologize if I'm just missing the obvious. I'm fairly new to Android development, and while I searched for this particular topic, I wasn't exactly sure what to look for (in terms of a "name").
In an application I'm writing, I have a section where the user can enter the names of players. However, this can range anywhere from 1 to whatever, no limit. However, I'm not sure what the best approach for this kind of feature is, or if there's a component that already does something like it.
Basically, the functionality I'm looking for is similar to what you can see in the Edit Contact screen of the phone book; for the phone numbers and email addresses, you can push a little plus button to add a new number/address, or hit the little minus button to remove a number/address.
I can think of several ways to potentially implement this, but in the end I think wrapping it in a custom component would be best (so that you could call "Get Players" and have it return a list of strings by going through each of the inputs and getting the values).
Am I just overthinking this? Is there a component that does that already? Is there some example code that demonstrates a good way to do this?
Thanks!
Could you just use ListView and add a menu with a "Add Players" option? You could customize the list view to have a little checkbox, for example, and then begin the game by pressing the menu ... or add new players dynamically by pressing another menu button.
After playing around with some ideas, I came across a solution that I think will suit what I'm doing. I created a custom component extending LinearLayout. As part of the creation of the component, it creates a row that says "Add new..." with a plus-sign button. Pressing the plus sign button then creates a new row containing an EditText and a minus-button which will remove the row.
I then created a method for this component called getTexts() which returns a List that has all the non-empty Text values from all the components. Testing it in a dummy app, it seemed to work fine.
I think I need to make tweaks to make it more robust (like the ability to add rows programatically, listeners to alert other components when a row is added/removed, and the ability to set the individual EditText values, for instance), but this functions as I imagined.

Categories

Resources