Android add new form and button dynamically - android

Currently working on an Android app. I want a page to have a button, and when clicked on, I want it to create a form. When they press the button again, it will create another form, and so on. Just like when you are on a website, and add your emails or anything, and you press "add" button, which will create a new input field each time.
Also, next to the input field has a name (same for each time) like
fieldName: [___input_field____]
fieldName: [___input_field____]
...
(+) //there is a button, and pressing this button will create a new form above.
I am not sure how to go about this. I want each input field to have a different ID, but is it possible? Each input field is going to be filled with a number, and in the end, I want to add all numbers in the form to find the average of them.

it will be easier and cleaner create a child layout with your form and inflate that child every time you need a new form and to get each item you can use View.getChildAt(position);

http://www.android-examples.com/create-edittext-dynamically-using-java-file-in-android/
This link shows a simple way to add an edittext dynamically. For what you have mentioned above, you have to use edittext array and for each "add" click, create edittext like et[i] = new EditText()...
Then on final submit click retrieve edittext datas from this editext array

Related

Creating a dynamic form inputs in android with ability to add an remove text fields

I would like to create a form in android in a fragment in which a user can add and remove form inputs
The below is an image which describes what i mean
As you can see there is an option to add a new row or even remove
Could somebody guide me on the way i would implement this, if possible with code snippets or external reference. I have researched and the samples provided arent clear
The provided resource is not clear because, take an instance where you on a button click you are to add a new edit text and set id to 1, next instance the id is supposed to be set to 2......without a limit to the user how do i implement such

Android: How to put each tuple returned from a SQL database as text on a button?

so I am making this app which currently connects to an external SQL database with a list of item names (I use php and json for this), and it displays these names as a textView. I followed this tutorial to learn this:
http://www.youtube.com/watch?v=4Soj22OMc98
However, what I really want to do is have the app have a button for EACH of the item names. Is there a way to make my app such that for each item name it pulls from the database, it creates a button, with the item's name as the text on that button?
This is very do-able. For each item name retrieved from your database, you need to programatically create a button and set the text attribute to the name.
Button b = new Button();
b.setText(insertNameHere);
Of course you also need to set the position of these buttons as well. This resource gives a good tutorial for creating buttons in this way: Tutorial

popup windows in android?

Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.

Editext validation for button click

I have an edittext and when the button is clicked it allows only Strings.
I do this by using an if statement to show a dialog with this condition: (str.matches("[0-9]*")
but when I enter this ttttt12323 and press the button it allows string and int to go through.
I want to put validation for not allowing string and text together specifically only Strings.
Can this be done. Thanks
So you want to check if your input consists of characters only, right?
You could try something like (str.matches("[A-Za-z]*")

Text inserted in the edittext is overwritten

I'm a beginner and am making a calculator (fairly easy), but it's happening the following problem: When Cline in "1" button for example, he enters this number in the EditText, but if you click again the number is overwritten instead of the inserted his side as desired. How do the numbers were placed side by side without overwriting those already there?
Note: The layout of buttons and etc. I did in. XML, so I'm not using the keyboard native Android.
Thanks!
when you want to add a new number next to the old one, you probably need to
get the value that is currently being shown in this "edit text" and save it in a string
concatenate this old value with the new one that you want to add to your "edit text"
set this new concatenated value as the new text in your "edit text"
:)

Categories

Resources