I want to set the button width during run time and I want it to be equal to 50% of the display width.
I used the following but I have a problem “nothing appears in emulator” and says
“Process stopped unexpectedly. Please try again”
.java
public class experiment extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Button btn = (Button) findViewById(R.id.btnmarwa);
btn.setWidth(width/2);
setContentView(R.layout.emailpopup);
}
}
When I commented this line
btn.setWidth(width);
There is no errors and the layout appears, So where to set the new width to the button in .java file??
Is not directly about your question, but you have to put this lines After setContentView() ’cause the findViewById method.
Like try this :