It looks to be a simple problem but I am struggling with it since 2 days ago.
I want to create a textView
dynamically on a Button Click.
Here is a sample piece of code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_main);
Button bn = (Button) findViewById(R.id.button2);
bn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TextView tv1 = new TextView(getApplicationContext());
tv1.setText("Show Up");
layout.addView(tv1);
}
});
}
I can see the button, but on clicking the button, I can't see the textView
in my layout.
Any issue in code?