-2

How to add a textview to layout at runtime when a Toggle button is clicked in the same Layout???

sagar
  • 13
  • 3
  • 1
    have you searched for "add textview dynamically". if so you may have found this: http://stackoverflow.com/questions/4203506/how-can-i-add-a-textview-to-a-linearlayout-dynamically-in-android – Bruno Bieri Nov 22 '12 at 08:41

2 Answers2

2

Here you have an example:

(On button Click)

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mylayout)
TextView txt1 = new TextView(MyClass.this);
linearLayout.setBackgroundColor(Color.TRANSPARENT);
linearLayout.addView(txt1);
Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
  • hey thanks fr the info i also need the textview to be vanished when i click the toggle to off state – sagar Nov 22 '12 at 08:50
0

Probably would be easier to just show/hide it. Use setVisibility(value), value could be View.GONE, View.INVISIBLE or View.VISIBLE.

Sergey Dmitriev
  • 454
  • 3
  • 13