Sunday, August 26, 2012

Add a Button - Programmetically

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;

public class HelloActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout m_linear = new LinearLayout(this);
        m_linear.setOrientation(LinearLayout.VERTICAL);
     
        Button m_button = new Button(this);
        m_button.setText("Hello World");
     
        m_linear.addView(m_button);
        setContentView(m_linear);
    }
}



No comments:

Post a Comment