How do I create a GUI in Android instead of using XML?… here is a solution to the problem.
How do I create a GUI in Android instead of using XML?
I
don’t like managing XML
and Java at the same time, can I create the same GUI using the Java
language?
How do I do this, can you tell me the code for a simple button
?
I would appreciate the correct answer.
Solution
Yes, you can.
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Button button = new Button(this);
button.setText("Press me!");
setContentView(button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Perform action on click
}
});
}
}