how to dynamically display the EditText? - android

i'm new to android. So can any one help me to get the following, when i enter the number in a EditText, the entered no.of EdidText should be appear dynamically. For example if i entered 3 in a EditText then, 3 EditText(no.of) have to be shown on the screen. How can i show this?

You need to add a TextWatcher to your EditText by calling EditText.addTextChangedListener(). Then in your TextWatcher wait for calls to afterTextChanged and count the characters and update your title. This will be easier if you make your Activity implement the the TextWatcher interface itself.

Add layout to your xml where you want to display the Edittext.
Then create the Layout variable e.g
LinearLayout ll = (LinearLayout)findViewById(R.id...);
and create new textboxes and add to the linearlayout e.g
EditText[] edit = new EditText[]();
EditText[] edit= new EditText[entered number];
initialize the variables in the loop by new Edittext(context);
and add each one to the Layout
`ll.addView(edit[iterator]);`

Related

How to generate multiple layout and get value of each filed in it in android

Actually i am going on with the page which has a add button if the user click add button it
should generate multiple layoutwith DropDown and edittext tried it programatically how can i take each value of dropDown
and edittext from all layout and pass it.
(for eg: if user click the button for 10 times it should generate 10 layout with the fields but the their is no limit for click).
If any other approach please help me out to solve this issue.
Tried:
LinearLayout linearLayout = (LinearLayout)getActivity().findViewById(R.id.progm_view);
EditText editText = new EditText(this);
editText.setId(i);
editText.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
linearLayout.addView(editText);
int i = edittext.getId();
editText.setTag("data");
EditText ed = (EditText)findViewByTag("data");
String text = ed.getText().toString();
Have an xml with dropdown and edittexts. Whenever user clicks, inflate the layout and add to the parent layout, so that you can user getChildAt(position) method to get each inflated layout so as to get the dropdown and edittext objects.

How to findviewbyid 100 EditTex in a TableLayout

I have put 100 edittext objects in a tablelayout,how could I use findviewbyid to find those editext objects ? so I could get the text from those edittext whcih user have entered ?
You can keep an ArrayList to hold the EditText like
ArrayList<EditText> editTextArray=new ArrayList<EditText>();
And add each EditText
editTextArray.add(editText1);
So , you can invoke as follows
editTextArray.get(i).getText();

Adding fields dynamically to a layout in Android

In my application, I want to add fields dynamically based on the selection. While there are 4 fixed spinner fields, the values of spinner are dependent on the selection of the first spinner field etc. The second spinner field has to be populated based on the first field and the third spinner field based on the second field and so on.
Based on the options selected in these 4 spinner fields, the layout will contain additional fields that are text fields or radio buttons etc.
Can someone suggest what is the best way to achieve this or refer to other examples for this?
Thanks
You can add a View to a Layout similar to the below code:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
(LayoutParams.WRAP_CONTENT), (LayoutParams.WRAP_CONTENT));
RelativeLayout relativeLayout = new RelativeLayout(mContext);
relativeLayout.setLayoutParams(layoutParams);
TextView view = new TextView(mContext);
view.setLayoutParams(layoutParams);
relativeLayout.addView(view);
And then you need to add it to an existing ViewLayout:
LinearLayout originalLayout = findViewById(R.id.mylayout);
originalLayout.addView(relativeLayout);
This idea can be expanded on to add custom Views etc to your screen.

Android EditText moving when MultiLine in TableRow

I have a Tablelayout with many TableRows inside. And inside these TableRows, many EditText. Like a spreadsheet.
My problem is the following: when something is wrote in the EditBox, the EditBoxs are still aligned:
But when the content of the EditBox goes to multi-line, my EditBox are not aligned anymore:
I thought that maybe the problem comes from the fact that my EditBox is not centered vertically in my TableRow, but this is something that I couldn't do.
Here is my code for the EditText, I add dynamically each EditText in my TableRows:
private EditText editTextCellule(int num, String texte, boolean pair){
EditText cellule = new EditText(this);
cellule.setLayoutParams(new TableRow.LayoutParams(num));
cellule.setWidth(LARGEUR_CELLULE);
cellule.setHeight(HAUTEUR_CELLULE);
cellule.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.text_size_medium_minus));
cellule.setText(texte);
cellule.setKeyListener( new PerfKeyListener() );
return cellule;
}
What can I do?
You provide layout weight to the following rows so they won't move.....
android:layout_weight = "1"
in table rows....

Can we have a part of a scrollable Listview (implemented using hashmap) non-scrollable?

Im using textview and edittexts to make a listview and using a hashmap to copy paste the layout. Now how do i get the values from the edit texts ? I tried it but it doesn't work because everytime we're using a new hashmap variable to create a copy and i didn't find anything like an array of hashmap variables.. Help needed.
My xml files :
MarksList>res>layout>marks_list_main :
Suppose you have added a LinearLayout as list item and on that Layout there is an edittext and a textview
LinearLayout layout=(LinearLayout) listView.getItemAtPosition(0);
EditText text = (EditText) layout.getChildAt(0); //Assuming you added EditText first
String s=text.getText().toString()

Categories

Resources