RadioButton r = (RadioButton) radioButton .getChildAt(idx); String selectedtext = r.getText().toString();
public void onClick(View v) { // 1) Possibly check for instance of first Button b = (Button)v; String buttonText = b.getText().toString(); }
public class Simple extends Base { private Simple(TextBox t) { super(t); // continue doing stuff with t here } public Simple() { this(new TextBox()); } }
@Override protected void onResume() { super.onResume(); Button button1 = (Button) findViewById(R.id.button1); button1.setEnabled(true); }
private void f(Button b, final int a) { final int[] res = new int[1]; b.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { res[0] = a*5; } }); // But at this point handler is most likely not executed yet! // How should we now res[0] is ready? }
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.weight = 1.0f; Button button = new Button(this); button.setLayoutParams(params);
Button button = (Button)findViewById(R.id.button1); button.setFocusable(true); button.setFocusableInTouchMode(true);///add this line button.requestFocus(); button.setText("Debug");
val incBtn = new Button("Increment") val label = new Label("0") label.text |= EventStreams.eventsOf(incBtn, ACTION) .accumulate(0, (n, a) => n + 1) .map(n => n.toString)
Drawable d = getResources().getDrawable(R.drawable.ic_launcher); Button one = new Button(this); // mediocre one.setBackgroundDrawable(d); Button two = new Button(this); // better two.setBackgroundResource(R.drawable.ic_launcher);
public void addPlaces() { Button button = new Button(getActivity()); // needs activity context // fragment hosted by a activity. use getActivity() to get the context of the hosting activity. button.setText("button name"); linearlayout.addView(button); }
Button n=(Button) findViewById(R.id.button1); Typeface typeface = Typeface.createFromAsset(getAssets(), "Helv Neue 67 Med Cond.ttf"); n.setText("show"); n.setTypeface(typeface);
LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(30, 20, 30, 0); Button okButton=new Button(this); okButton.setText("some text"); ll.addView(okButton, layoutParams);
Button buttonNo = alert.getButton(AlertDialog.BUTTON_NEGATIVE); buttonNo.setEnabled(false);
LinearLayout myLayout = findViewById(R.id.main); Button myButton = new Button(this); myButton.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); myLayout.addView(myButton);
public class MyActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); ListView v = getListView(); v.addFooterView(new Button(this)); } }
View.OnClickListener getOnClickDoSomething(final Button button) { return new View.OnClickListener() { public void onClick(View v) { button.setText("text now set.. "); } }; }
if(rg1.getCheckedRadioButtonId()!=-1){ int id= rg1.getCheckedRadioButtonId(); View radioButton = rg1.findViewById(id); int radioId = radioGroup.indexOfChild(radioButton); RadioButton btn = (RadioButton) rg1.getChildAt(radioId); String selection = (String) btn.getText(); }
Button btn = (Button) findViewById(R.id.button1); btn.setEnabled(true);
Button btn = (Button) findViewById(R.id.button1); btn.setEnabled(false);