Example usage for android.widget LinearLayout setOrientation

List of usage examples for android.widget LinearLayout setOrientation

Introduction

In this page you can find the example usage for android.widget LinearLayout setOrientation.

Prototype

public void setOrientation(@OrientationMode int orientation) 

Source Link

Document

Should the layout be a column or a row.

Usage

From source file:org.nativescript.widgets.TabLayout.java

/**
 * Create a default view to be used for tabs.
 *///from  ww w  . j  a  v a 2 s .c  om
protected View createDefaultTabView(Context context, TabItemSpec tabItem) {
    float density = getResources().getDisplayMetrics().density;
    int padding = (int) (TAB_VIEW_PADDING_DIPS * density);

    LinearLayout ll = new LinearLayout(context);
    ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setGravity(Gravity.CENTER);
    ll.setOrientation(LinearLayout.VERTICAL);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    ll.setBackgroundResource(outValue.resourceId);

    ImageView imgView = new ImageView(context);
    imgView.setScaleType(ScaleType.FIT_CENTER);
    LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgLP.gravity = Gravity.CENTER;
    imgView.setLayoutParams(imgLP);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setMaxWidth((int) (TEXT_MAX_WIDTH * density));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setAllCaps(true);
    textView.setMaxLines(2);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setPadding(padding, 0, padding, 0);

    this.setupItem(ll, textView, imgView, tabItem);

    ll.addView(imgView);
    ll.addView(textView);
    return ll;
}

From source file:org.dvbviewer.controller.ui.base.BaseListFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 * //from  www  .  ja  v  a  2 s .  c o  m
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *
 * @param inflater the inflater
 * @param container the container
 * @param savedInstanceState the saved instance state
 * @return the view
 * @author RayBa
 * @date 07.04.2013
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();
    if (layoutRessource > 0) {
        View v = getLayoutInflater(savedInstanceState).inflate(layoutRessource, null);
        return v;
    } else {
        FrameLayout root = new FrameLayout(context);

        // ------------------------------------------------------------------

        LinearLayout pframe = new LinearLayout(context);
        pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
        pframe.setOrientation(LinearLayout.VERTICAL);
        pframe.setVisibility(View.GONE);
        pframe.setGravity(Gravity.CENTER);

        ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyle);
        pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));

        root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        // ------------------------------------------------------------------

        FrameLayout lframe = new FrameLayout(context);
        lframe.setId(INTERNAL_LIST_CONTAINER_ID);

        TextView tv = new TextView(getActivity());
        tv.setId(INTERNAL_EMPTY_ID);
        tv.setGravity(Gravity.CENTER);
        tv.setTextAppearance(getActivity(), android.R.style.TextAppearance_Medium);
        lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        ListView lv = new ListView(getActivity());
        lv.setId(android.R.id.list);
        lv.setDrawSelectorOnTop(false);
        lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        // ------------------------------------------------------------------

        root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        return root;
    }
}

From source file:eu.hydrologis.geopaparazzi.maptools.FeaturePageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Feature feature = featuresList.get(position);

    int bgColor = context.getResources().getColor(R.color.formbgcolor);
    int textColor = context.getResources().getColor(R.color.formcolor);

    ScrollView scrollView = new ScrollView(context);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);/*  w ww. ja  v a  2s  .  c om*/
    scrollLayoutParams.setMargins(10, 10, 10, 10);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setBackgroundColor(bgColor);

    LinearLayout linearLayoutView = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    int margin = 10;
    layoutParams.setMargins(margin, margin, margin, margin);
    linearLayoutView.setLayoutParams(layoutParams);
    linearLayoutView.setOrientation(LinearLayout.VERTICAL);
    int padding = 10;
    linearLayoutView.setPadding(padding, padding, padding, padding);
    scrollView.addView(linearLayoutView);

    List<String> attributeNames = feature.getAttributeNames();
    List<String> attributeValues = feature.getAttributeValuesStrings();
    List<String> attributeTypes = feature.getAttributeTypes();
    for (int i = 0; i < attributeNames.size(); i++) {
        final String name = attributeNames.get(i);
        String value = attributeValues.get(i);
        String typeString = attributeTypes.get(i);
        DataType type = DataType.getType4Name(typeString);

        TextView textView = new TextView(context);
        textView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(padding, padding, padding, padding);
        textView.setText(name);
        textView.setTextColor(textColor);
        // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        linearLayoutView.addView(textView);

        final EditText editView = new EditText(context);
        LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        editViewParams.setMargins(margin, 0, margin, 0);
        editView.setLayoutParams(editViewParams);
        editView.setPadding(padding * 2, padding, padding * 2, padding);
        editView.setText(value);
        //            editView.setEnabled(!isReadOnly);
        editView.setFocusable(!isReadOnly);
        // editView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        if (isReadOnly) {
            editView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    String text = editView.getText().toString();
                    FeatureUtilities.viewIfApplicable(v.getContext(), text);
                    return false;
                }
            });
        }

        switch (type) {
        case DOUBLE:
        case FLOAT:
            editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            break;
        case PHONE:
            editView.setInputType(InputType.TYPE_CLASS_PHONE);
            break;
        case DATE:
            editView.setInputType(InputType.TYPE_CLASS_DATETIME);
            break;
        case INTEGER:
            editView.setInputType(InputType.TYPE_CLASS_NUMBER);
            break;
        default:
            break;
        }

        editView.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // ignore
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // ignore
            }

            public void afterTextChanged(Editable s) {
                String text = editView.getText().toString();
                feature.setAttribute(name, text);
            }
        });

        linearLayoutView.addView(editView);
    }

    /*
     * add also area and length
     */
    if (feature.getOriginalArea() > -1) {
        TextView areaTextView = new TextView(context);
        areaTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        areaTextView.setPadding(padding, padding, padding, padding);
        areaTextView.setText("Area: " + areaLengthFormatter.format(feature.getOriginalArea()));
        areaTextView.setTextColor(textColor);
        TextView lengthTextView = new TextView(context);
        lengthTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        lengthTextView.setPadding(padding, padding, padding, padding);
        lengthTextView.setText("Length: " + areaLengthFormatter.format(feature.getOriginalLength()));
        lengthTextView.setTextColor(textColor);
        linearLayoutView.addView(areaTextView);
        linearLayoutView.addView(lengthTextView);
    }
    container.addView(scrollView);

    return scrollView;
}

From source file:com.app.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject /*from  w  w w . j  a  va2 s.  com*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", false);
    }

    final WebView parent = this.webView;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            //LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(cordova.getActivity());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            /*
            ImageButton back = new ImageButton((Context) ctx);
            back.getBackground().setAlpha(0);
            back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goBack();
            }
            });
            back.setId(1);
            try {
            back.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);
                    
            ImageButton forward = new ImageButton((Context) ctx);
            forward.getBackground().setAlpha(0);
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
            forward.setId(2);
            try {
            forward.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }               
            forward.setLayoutParams(forwardParams);
            */

            /*
            edittext = new EditText((Context) ctx);
            edittext.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  navigate(edittext.getText().toString());
                  return true;
                }
                return false;
            }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);
            */
            //edittext = new EditText((Context) ctx);
            //edittext.setVisibility(View.GONE);

            LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.FILL_PARENT, 1.0f);
            TextView title = new TextView(cordova.getActivity());
            title.setId(1);
            title.setLayoutParams(titleParams);
            title.setGravity(Gravity.CENTER_VERTICAL);
            title.setTypeface(null, Typeface.BOLD);

            ImageButton close = new ImageButton(cordova.getActivity());
            close.getBackground().setAlpha(0);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("plugins/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            childWebView = new WebView(cordova.getActivity());
            childWebView.getSettings().setJavaScriptEnabled(true);
            childWebView.getSettings().setBuiltInZoomControls(true);
            WebViewClient client = new ChildBrowserClient(parent, ctx, title/*, edittext*/);
            childWebView.setWebViewClient(client);
            childWebView.loadUrl(url);
            childWebView.setId(5);
            childWebView.setInitialScale(0);
            childWebView.setLayoutParams(wvParams);
            childWebView.requestFocus();
            childWebView.requestFocusFromTouch();

            //toolbar.addView(back);
            //toolbar.addView(forward);
            //toolbar.addView(edittext);
            toolbar.addView(close);
            toolbar.addView(title);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(childWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;
            lp.verticalMargin = 0f;
            lp.horizontalMargin = 0f;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:jp.mau.twappremover.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        ScrollView contents = new ScrollView(this);
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        contents.addView(layout);//from  w w w.  j  av  a  2s.c o m
        AssetManager asm = getResources().getAssets();
        String[] filelist = null;
        try {
            filelist = asm.list("licenses");
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        if (filelist != null) {
            for (String file : filelist) {
                Gen.debug(file);
                InputStream is = null;
                BufferedReader br = null;
                String txt = "";
                try {
                    is = getAssets().open("licenses/" + file);
                    br = new BufferedReader(new InputStreamReader(is));
                    String str;
                    while ((str = br.readLine()) != null) {
                        txt += str + "\n";
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {
                    try {
                        if (is != null)
                            is.close();
                    } catch (Exception ex) {
                    }
                    try {
                        if (br != null)
                            br.close();
                    } catch (Exception ex) {
                    }
                }
                TextView tv = new TextView(this);
                tv.setText(txt);
                layout.addView(tv);
            }
        }

        // 
        final PopupView dialog = new PopupView(this);
        dialog.setDialog().setLabels(getString(R.string.activity_main_dlgtitle_oss), "")
                .setView(contents, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .setCancelable(true)
                .setPositiveBtn(getString(R.string.activity_main_dlgbtn_oss), new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                }).show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.bhb27.isu.Props.java

private void EditProps(String[] props) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    TextView descriptionText = new TextView(getActivity());
    descriptionText.setText(getString(R.string.props_any_edit_dialog_summary));
    linearLayout.addView(descriptionText);

    ScrollView scrollView = new ScrollView(getActivity());
    scrollView.setPadding(0, 0, 0, 10);//  ww  w .  j  a va  2 s.  c om
    linearLayout.addView(scrollView);

    LinearLayout editLayout = new LinearLayout(getActivity());
    editLayout.setOrientation(LinearLayout.VERTICAL);
    scrollView.addView(editLayout);

    final AppCompatEditText[] EditProps = new AppCompatEditText[props.length];
    final AppCompatCheckBox[] ForceBP = new AppCompatCheckBox[props.length];
    final TextView[] descriptionAboveText = new TextView[props.length];
    final TextView[] descriptionBelowText = new TextView[props.length];

    for (int i = 0; i < props.length; i++) {
        descriptionAboveText[i] = new TextView(getActivity());
        descriptionAboveText[i].setText(String.format(getString(R.string.empty), props[i]));
        editLayout.addView(descriptionAboveText[i]);

        EditProps[i] = new AppCompatEditText(getActivity());
        EditProps[i].setText(Tools.getprop(props[i]));
        editLayout.addView(EditProps[i]);

        descriptionBelowText[i] = new TextView(getActivity());
        descriptionBelowText[i].setText(getString(R.string.props_any_edit_dialog_already_bp));
        ForceBP[i] = new AppCompatCheckBox(getActivity());
        ForceBP[i].setText(getString(R.string.props_any_edit_dialog_force_bp));

        if (Tools.PropIsinbp(props[i], getActivity()))
            editLayout.addView(descriptionBelowText[i]);
        else
            editLayout.addView(ForceBP[i]);
    }

    new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle)
            .setTitle(getString(R.string.props_any_edit_dialog_title)).setView(linearLayout)
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    return;
                }
            }).setPositiveButton(getString(R.string.apply), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int id) {
                    String finalmenssage = "\n", edited;
                    for (int i = 0; i < props.length; i++) {
                        edited = EditProps[i].getText().toString();
                        if (edited.isEmpty()) {
                            finalmenssage = finalmenssage
                                    + String.format(getString(R.string.edited_text_ro), props[i]);
                        } else if (edited.equals(Tools.getprop(props[i])))
                            finalmenssage = finalmenssage
                                    + String.format(getString(R.string.edited_text_equals), props[i]);
                        else {
                            if (((AppCompatCheckBox) ForceBP[i]).isChecked())
                                Tools.resetprop(executableFilePath, props[i], edited, getActivity(), true);
                            else
                                Tools.resetprop(executableFilePath, props[i], edited, getActivity(), false);
                            finalmenssage = finalmenssage
                                    + String.format(getString(R.string.edited_text_ok), props[i]);
                            save_prop(props[i], edited);
                        }
                        finalmenssage = finalmenssage + "\n";
                    }
                    finaldialogro(finalmenssage);
                    return;
                }
            }).show();
}

From source file:jfabrix101.lib.fragmentActivity.AbstractFragmentActivityController.java

/**
 * Crea un layout verticale utilizzando il solo fragment di sinistra (la lista)
 */// w ww  .j ava2 s .  c  o m
@SuppressWarnings("all")
protected View makeLeftPortraitLayout(LayoutInflater inflater) {
    if (getLayoutResourceId() > 0) {
        View v = LayoutInflater.from(this).inflate(getLayoutResourceId(), null);
        View rightFragment = v.findViewById(getRightFragmentId());
        if (rightFragment != null) {
            rightFragment.setVisibility(View.GONE);
        }
        mVisualizationMode = VisualizationMode.PORTRAIT_ONLY_LEFT;
        return v;
    } else {
        LinearLayout layout = new LinearLayout(this);

        layout.setPadding(10, 10, 10, 10);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        layout.setOrientation(LinearLayout.VERTICAL);

        FrameLayout leftFrame = new FrameLayout(this);
        leftFrame.setId(getLeftFragmentId());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
        leftFrame.setLayoutParams(lp);

        layout.addView(leftFrame);
        mVisualizationMode = VisualizationMode.PORTRAIT_ONLY_LEFT;
        return layout;
    }
}

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java

@Override
public void createAndAttachSelectQuestionDropdown(Question question, LinearLayout sectionLinearLayout) {
    TextView textView = new TextView(getActivity());
    textView.setPadding(20, 0, 0, 0);//  w ww.j  a v a  2 s.co  m
    textView.setText(question.getLabel());
    Spinner spinner = (Spinner) getActivity().getLayoutInflater().inflate(R.layout.form_dropdown, null);

    LinearLayout questionLinearLayout = new LinearLayout(getActivity());
    LinearLayout.LayoutParams questionLinearLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    questionLinearLayout.setOrientation(LinearLayout.VERTICAL);
    questionLinearLayoutParams.gravity = Gravity.START;
    questionLinearLayout.setLayoutParams(questionLinearLayoutParams);

    List<String> answerLabels = new ArrayList<>();
    for (Answer answer : question.getQuestionOptions().getAnswers()) {
        answerLabels.add(answer.getLabel());
    }

    SelectOneField spinnerField = new SelectOneField(question.getQuestionOptions().getAnswers(),
            question.getQuestionOptions().getConcept());

    ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item,
            answerLabels);
    spinner.setAdapter(arrayAdapter);

    LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    questionLinearLayout.addView(textView);
    questionLinearLayout.addView(spinner);

    sectionLinearLayout.setLayoutParams(linearLayoutParams);
    sectionLinearLayout.addView(questionLinearLayout);

    SelectOneField selectOneField = getSelectOneField(spinnerField.getConcept());
    if (selectOneField != null) {
        spinner.setSelection(selectOneField.getChosenAnswerPosition());
        setOnItemSelectedListener(spinner, selectOneField);
    } else {
        setOnItemSelectedListener(spinner, spinnerField);
        selectOneFields.add(spinnerField);
    }
}

From source file:jfabrix101.lib.fragmentActivity.AbstractFragmentActivityController.java

/**
 * Crea un layout in landscape utilizzando due fragment di peso proporzionale
 * Per cambiare le dimensioni dei pesi effettuare l'override dei 
 * metodi <code>getLeftFragmentSize</code> e <code>getRightFragmentSize</code> 
 *//*from w  w w .  ja  va  2  s.  c o  m*/
@SuppressWarnings("all")
protected View makeLandscapeLayout(LayoutInflater inflater) {
    if (getLayoutResourceId() > 0) {
        View v = inflater.inflate(getLayoutResourceId(), null);
        mVisualizationMode = VisualizationMode.LANDSCAPE;
        return v;
    } else {
        LinearLayout layout = new LinearLayout(this);
        layout.setPadding(10, 10, 10, 10);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        layout.setOrientation(LinearLayout.HORIZONTAL);

        FrameLayout leftFrame = new FrameLayout(this);
        leftFrame.setId(getLeftFragmentId());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT,
                getLeftFragmentWeigth());
        leftFrame.setLayoutParams(lp);

        FrameLayout rightFrame = new FrameLayout(this);
        rightFrame.setId(getRightFragmentId());
        lp = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, getRightFragmentWeigth());
        rightFrame.setLayoutParams(lp);

        layout.addView(leftFrame);
        layout.addView(rightFrame);
        mVisualizationMode = VisualizationMode.LANDSCAPE;
        return layout;
    }

}

From source file:jfabrix101.lib.fragmentActivity.AbstractFragmentActivityController.java

/**
 * Crea un layout verticale utilizzando il solo fragment di destra (il dettaglio)
 *///  w ww  .ja  v a 2  s  .c o m
@SuppressWarnings("all")
protected View makeRightPortraitLayout(LayoutInflater inflater) {
    if (getLayoutResourceId() > 0) {
        View v = LayoutInflater.from(this).inflate(getLayoutResourceId(), null);
        View leftFragment = v.findViewById(getLeftFragmentId());
        if (leftFragment != null) {
            leftFragment.setVisibility(View.GONE);
        }
        mVisualizationMode = VisualizationMode.PORTRAIT_ONLY_RIGHT;
        //         getActionBar().setDisplayHomeAsUpEnabled(true); 
        return v;
    } else {
        LinearLayout layout = new LinearLayout(this);

        layout.setPadding(10, 10, 10, 10);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        layout.setOrientation(LinearLayout.VERTICAL);

        FrameLayout rightFrame = new FrameLayout(this);
        rightFrame.setId(getRightFragmentId());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
        rightFrame.setLayoutParams(lp);

        layout.addView(rightFrame);
        mVisualizationMode = VisualizationMode.PORTRAIT_ONLY_RIGHT;
        //         getActionBar().setDisplayHomeAsUpEnabled(true); 
        return layout;
    }
}