/** Creates a standard spinner and adds it to the layout. */ public <T> Spinner addSpinner(int spinnerId, ArrayAdapter<T> arrayAdapter) { Spinner spinner = (Spinner) LayoutInflater.from(getContext()) .inflate(R.layout.infobar_control_spinner, this, false); spinner.setAdapter(arrayAdapter); addView(spinner, new ControlLayoutParams()); spinner.setId(spinnerId); return spinner; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a simple layout LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); // Create the spinner to allow the user to choose a menu XML ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, sMenuExampleNames); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner = new Spinner(this); // When programmatically creating views, make sure to set an ID // so it will automatically save its instance state mSpinner.setId(R.id.spinner); mSpinner.setAdapter(adapter); mSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { invalidateOptionsMenu(); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); // Add the spinner layout.addView( mSpinner, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); // Create help text mInstructionsText = new TextView(this); mInstructionsText.setText( getResources().getString(R.string.menu_from_xml_instructions_press_menu)); // Add the help, make it look decent LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(10, 10, 10, 10); layout.addView(mInstructionsText, lp); // Set the layout as our content view setContentView(layout); }
/** {@inheritDoc} */ @Override protected void onFinishInflate() { mLabel = (Spinner) findViewById(R.id.spinner); // Turn off the Spinner's own state management. We do this ourselves on rotation mLabel.setId(View.NO_ID); mLabel.setOnItemSelectedListener(mSpinnerListener); mDelete = (ImageView) findViewById(R.id.delete_button); mDeleteContainer = findViewById(R.id.delete_button_container); mDeleteContainer.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // defer removal of this button so that the pressed state is visible shortly new Handler() .post( new Runnable() { @Override public void run() { // Don't do anything if the view is no longer attached to the window // (This check is needed because when this {@link Runnable} is executed, // we can't guarantee the view is still valid. if (!mIsAttachedToWindow) { return; } // Send the delete request to the listener (which will in turn call // deleteEditor() on this view if the deletion is valid - i.e. this is not // the last {@link Editor} in the section). if (mListener != null) { mListener.onDeleteRequested(LabeledEditorView.this); } } }); } }); setPadding( getPaddingLeft(), getPaddingTop(), getPaddingRight(), (int) getResources().getDimension(R.dimen.editor_padding_between_editor_views)); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(LT, "App created."); Events.intEnableDebug(1); // disable the titlebar requestWindowFeature(Window.FEATURE_NO_TITLE); // create a basic user interface LinearLayout panel = new LinearLayout(this); panel.setOrientation(LinearLayout.VERTICAL); setContentView(panel); // -- Button b = new Button(this); b.setText("Scan Input Devs"); b.setId(idButScan); b.setOnClickListener(this); panel.addView(b); // -- m_lvDevices = new ListView(this); m_lvDevices.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); m_lvDevices.setId(idLVDevices); m_lvDevices.setDividerHeight(0); m_lvDevices.setFadingEdgeLength(0); m_lvDevices.setCacheColorHint(0); m_lvDevices.setAdapter(null); panel.addView(m_lvDevices); // -- LinearLayout panelH = new LinearLayout(this); panelH.setOrientation(LinearLayout.HORIZONTAL); panel.addView(panelH); // -- m_selDevSpinner = new Spinner(this); m_selDevSpinner.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); m_selDevSpinner.setId(idSelSpin); m_selDevSpinner.setOnItemSelectedListener((OnItemSelectedListener) this); panelH.addView(m_selDevSpinner); // -- simulate key event b = new Button(this); b.setText(">Key"); b.setId(idButInjectKey); b.setOnClickListener(this); panelH.addView(b); // -- simulate touch event b = new Button(this); b.setText(">Tch"); b.setId(idButInjectTouch); b.setOnClickListener(this); panelH.addView(b); // -- m_tvMonitor = new TextView(this); m_tvMonitor.setText("Event Monitor stopped."); panel.addView(m_tvMonitor); // -- panelH = new LinearLayout(this); panelH.setOrientation(LinearLayout.HORIZONTAL); panel.addView(panelH); // -- b = new Button(this); b.setText("Monitor Start"); b.setId(idButMonitorStart); b.setOnClickListener(this); panelH.addView(b); // -- b = new Button(this); b.setText("Monitor Stop"); b.setId(idButMonitorStop); b.setOnClickListener(this); panelH.addView(b); // -- simulate test event b = new Button(this); b.setText(">Test"); b.setId(idButTest); b.setOnClickListener(this); panelH.addView(b); }
void dialogAdd(int id, int type, String name, String value, int selection) { switch (type) { case C_STRING: { dialogIds.add(id); EditText et = new EditText(SGTPuzzles.this); // TODO: C_INT, C_UINT, C_UDOUBLE, C_DOUBLE // Ugly temporary hack: in custom game dialog, all text boxes are numeric, in the other // two dialogs they aren't. // Uglier temporary-er hack: Black Box must accept a range for ball count. if (configIsCustom && !helpTopic.equals("blackbox")) et.setInputType( InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); et.setId(id); et.setText(value); TextView tv = new TextView(SGTPuzzles.this); tv.setText(name); tv.setPadding(2, 2, 2, 2); TableRow tr = new TableRow(SGTPuzzles.this); tr.addView(tv); tr.addView(et); dialogLayout.addView(tr); break; } case C_BOOLEAN: { dialogIds.add(id); CheckBox c = new CheckBox(SGTPuzzles.this); c.setId(id); c.setText(name); c.setChecked(selection != 0); dialogLayout.addView(c); break; } case C_CHOICES: { StringTokenizer st = new StringTokenizer(value.substring(1), value.substring(0, 1)); ArrayList<String> choices = new ArrayList<String>(); while (st.hasMoreTokens()) choices.add(st.nextToken()); dialogIds.add(id); Spinner s = new Spinner(SGTPuzzles.this); s.setId(id); ArrayAdapter<String> a = new ArrayAdapter<String>( SGTPuzzles.this, android.R.layout.simple_spinner_item, choices.toArray(new String[0])); a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(a); s.setSelection(selection); TextView tv = new TextView(SGTPuzzles.this); tv.setText(name); TableRow tr = new TableRow(SGTPuzzles.this); tr.addView(tv); tr.addView(s); dialogLayout.addView(tr); break; } } }
private View getView(int mId, cl.tdc.felipe.tdc.objects.Relevar.Item item) { String type = item.getType(); List<String> values = item.getValues(); LinearLayout contenido = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); contenido.setLayoutParams(params); params.setMargins(0, 6, 0, 0); contenido.setOrientation(LinearLayout.VERTICAL); contenido.setGravity(Gravity.CENTER_HORIZONTAL); String comment = ""; if (type.equals("SELECT")) { Spinner s = new Spinner(this); s.setBackgroundResource(R.drawable.spinner_bg); s.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, values); s.setAdapter(adapter); String id = mId + item.getId() + item.getName() + values.toString(); s.setId(Funciones.str2int(id)); String Selected = reg.getString("SELECT" + s.getId()); s.setSelection(adapter.getPosition(Selected)); contenido.addView(s); item.setVista(s); comment = reg.getString("COMMENTSELECT" + s.getId()); } else if (type.equals("CHECK")) { LinearLayout checkboxLayout = new LinearLayout(this); checkboxLayout.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); checkboxLayout.setOrientation(LinearLayout.VERTICAL); ArrayList<CheckBox> checkBoxes = new ArrayList<>(); int count = 0; while (count < values.size()) { LinearLayout dump = new LinearLayout(this); dump.setOrientation(LinearLayout.HORIZONTAL); dump.setGravity(Gravity.CENTER_HORIZONTAL); dump.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int p = 0; p < 3; p++) { if (count < values.size()) { String state = values.get(count); CheckBox cb = new CheckBox(this); String id = mId + item.getId() + item.getName() + values.get(count); cb.setId(Funciones.str2int(id)); cb.setChecked(reg.getBoolean("CHECK" + cb.getId())); cb.setText(state); checkBoxes.add(cb); dump.addView(cb); if (count == 0) comment = reg.getString("COMMENTCHECK" + cb.getId()); count++; vistas.add(cb); } } checkboxLayout.addView(dump); } makeOnlyOneCheckable(checkBoxes); item.setCheckBoxes(checkBoxes); contenido.addView(checkboxLayout); } else if (type.equals("NUM")) { EditText e = new EditText(this); e.setBackgroundResource(R.drawable.fondo_edittext); e.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); String id = mId + item.getId() + item.getName(); e.setId(Funciones.str2int(id)); e.setText(reg.getString("TEXT" + e.getId())); e.setLayoutParams(new LinearLayout.LayoutParams(100, ViewGroup.LayoutParams.WRAP_CONTENT)); e.setGravity(Gravity.CENTER_HORIZONTAL); vistas.add(e); item.setVista(e); contenido.addView(e); comment = reg.getString("COMMENTTEXT" + e.getId()); } else if (type.equals("VARCHAR")) { EditText e = new EditText(this); e.setBackgroundResource(R.drawable.fondo_edittext); e.setInputType(InputType.TYPE_CLASS_TEXT); e.setLines(2); e.setGravity(Gravity.LEFT | Gravity.TOP); String id = mId + item.getId() + item.getName(); e.setId(Funciones.str2int(id)); e.setText(reg.getString("TEXT" + e.getId())); vistas.add(e); item.setVista(e); contenido.addView(e); comment = reg.getString("COMMENTTEXT" + e.getId()); } if (!item.getName().equals("COMENTARIOS")) { EditText comentario = new EditText(this); comentario.setLayoutParams(params); comentario.setBackgroundResource(R.drawable.fondo_edittext); comentario.setLines(3); comentario.setText(comment); comentario.setHint("Observaciones"); item.setDescription(comentario); contenido.addView(comentario); } return contenido; }