Created
November 14, 2015 11:06
-
-
Save Vaikesh/1ee4179240fab271dd31 to your computer and use it in GitHub Desktop.
Create a textview and Edittext dynamically when a button is clicked.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.App; | |
using Android.Content; | |
using Android.Runtime; | |
using Android.Views; | |
using Android.Widget; | |
using Android.OS; | |
namespace DynamicControl | |
{ | |
[Activity (Label = "DynamicControl", MainLauncher = true, Icon = "@drawable/icon")] | |
public class MainActivity : Activity | |
{ | |
int count = 0; | |
protected override void OnCreate (Bundle bundle) | |
{ | |
base.OnCreate (bundle); | |
ScrollView _scrl = new ScrollView (this); | |
LinearLayout _linear = new LinearLayout (this); | |
_linear.Orientation = Orientation.Vertical; | |
_scrl.AddView (_linear); | |
Button _addBtn = new Button (this); | |
_addBtn.Text = "Click to add TextViiews and EditTexts"; | |
_linear.AddView (_addBtn); | |
_addBtn.Click += (sender, e) => { | |
// TODO Auto-generated method stub | |
count++; | |
TextView _text = new TextView (ApplicationContext); | |
_text.Text = "Number : " + count.ToString(); | |
_linear.AddView(_text); | |
EditText _edit = new EditText(ApplicationContext); | |
_edit.Text = " Edit Text : " + count.ToString(); | |
_linear.AddView(_edit); | |
}; | |
this.SetContentView (_scrl); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment