Tag Archives: dynamically

9,436 views

Set Drawable programmatically Android example

// start_dark.png is stored in path /package_name/res/drawable/start_dark.png Drawable dw = getApplicationContext().getResources().getDrawable(R.drawable.start_dark); Button hButtonStart = (Button)findViewById(R.id.buttonStart); hButtonStart.setCompoundDrawablesWithIntrinsicBounds(dw, null, null, null);

Posted in Android Examples Code | Tagged , | Comments Off on Set Drawable programmatically Android example
7,754 views

Create the Menu MenuItem dynamically Android example

public class MyActivity extends Activity { // http://www.apache.org/licenses/LICENSE-2.0   @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } // set ID private static final int MY_MENU_1 = Menu.FIRST; private static final int MY_MENU_2 = Menu.FIRST + 1; private static … Continue reading

Posted in Android Examples Code | Tagged , , | Comments Off on Create the Menu MenuItem dynamically Android example
23,759 views

Create RadioButton RadioGroup dynamically – Android sample

public class MainActivity extends Activity implements OnClickListener {   @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);   LinearLayout layout = (LinearLayout) findViewById(R.id.layout); RadioGroup radioGroup = new RadioGroup(this);   LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); layout.addView(radioGroup, p);   … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Create RadioButton RadioGroup dynamically – Android sample
13,061 views

Create Button and TextView dynamically – Android sample

public class MainActivity extends Activity {   @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);   LinearLayout layout = (LinearLayout) findViewById(R.id.layout); TextView textView = new TextView(this); textView.setText("Text View "); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); layout.addView(textView, p);   … Continue reading

Posted in Android Examples Code | Tagged , , , | Comments Off on Create Button and TextView dynamically – Android sample
11,376 views

Adding TableRow add row with a View TextView dynamically to TableLayout Android sample example

Adding TableRow with a View TextView (EditText Button) programmically dynamically to TableLayout Android sample basic example. MainClass.java public class MainClass extends Activity {   @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);   TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1); TableRow row = … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Adding TableRow add row with a View TextView dynamically to TableLayout Android sample example
8,970 views

Create TextView dynamically Android sample

Example source code for Android Developers // clickable TextView public TextView createTextView(String sText, Context con){ TextView b = null; try { b = new TextView (con); b.setTextSize(15.0f); b.setTextColor(Color.rgb( 0, 0, 200)); b.setOnClickListener(this); b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); b.setText(sText); //tr.addView(b, 60,30); } catch … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Create TextView dynamically Android sample