Reputation: 29
I wanted to set textview programmatically, the below code doesn't seem to work
TextView textView = new TextView(this);
textView.setText("game");
setContentView(textView);
Upvotes: 0
Views: 72
Reputation: 1045
create LayoutParams
as following
LayoutParams param=new LayoutParams(w, h);
textView.setLayoutParams(param);
Upvotes: 0
Reputation: 2979
try this
TextView textView = new TextView(this);
textView.setText("game");
textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
setContentView(textView);
Upvotes: 0
Reputation: 3585
Change
TextView textView = new TextView(this);
to
TextView textView = new TextView(Youractivity.this);
Upvotes: 1
Reputation: 989
remove setContentView(....);
anywhere before TextView textView = new TextView(this);
Upvotes: 0