Skip to content Skip to sidebar Skip to footer

Formatting Dynamic Edittext Android

ANDROID I have a layout defined in xml and have a static textview, edittext and checkboxes which are all formatted as below: android:layout_width='0px' android:layout_height='wrap_

Solution 1:

You can add the layout by inflating each time you need textview, edittext and chekbox.This way your layout will have same look.Because you are reusing your static layout in xml.

See Layout Inflating for details

You have a layout with textview,edittext and checkbox.Now you will use the layout as a view.Like you said for each row you have to inflate the layout and add it to the row.So for every row you will have the copy of the layout.

TableLayout layout=(TableLayout)findViewById(R.id.tblLayout);

Now you can add the view after inflating the layout

   View rowView = inflater.inflate(R.layout.row_layout, null, true);
   TableRow tblrow=new TableRow(this);
   tblRow.add(rowView);
   layout.add(tblRow);

Solution 2:

You can create any control Dynamic like this way.

Here i show for Edit Text same way you can do for others.

EditTextet=newEditText(this);  
 et.setText("");
 et.setLayoutParams(newLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

Solution 3:

Use the following code for dynamic configurations about EditText.

EditText my_edit = (EditText) findViewById(R.id.my_edit);

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.weight = 2.0f;
my_edit.setLayoutParams(params);
my_edit.setTextSize(20);
my_edit.setWidth(180);
my_edit.setSingleLine(true);

For this you must need LinearLayout as a parent of your EditText.

I hope this helps you somehow.

Thanks.

Post a Comment for "Formatting Dynamic Edittext Android"