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:pl.bcichecki.rms.client.android.dialogs.RegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    context = getActivity();/*from w w w  .  j  ava2s.co m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(getString(R.string.dialog_register_title));
    builder.setMessage(getString(R.string.dialog_register_message));

    final EditText usernameEditText = new EditText(getActivity());
    usernameEditText.setHint(getString(R.string.dialog_register_enter_username_hint));
    usernameEditText.setMaxLines(1);
    usernameEditText.setSingleLine();
    usernameEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    usernameEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            usernameEditText.setError(null);
        }

    });

    final EditText passwordEditText = new EditText(getActivity());
    passwordEditText.setHint(getString(R.string.dialog_register_enter_password_hint));
    passwordEditText.setMaxLines(1);
    passwordEditText.setSingleLine();
    passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    passwordEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            passwordEditText.setError(null);
        }

    });

    final EditText emailEditText = new EditText(getActivity());
    emailEditText.setHint(getString(R.string.dialog_register_enter_email_hint));
    emailEditText.setMaxLines(1);
    emailEditText.setSingleLine();
    emailEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    emailEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            emailEditText.setError(null);
        }

    });

    final LinearLayout layout = new LinearLayout(getActivity());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    int space = (int) AppUtils.convertDpToPixel(getActivity(), 16);
    layout.setPadding(space, 0, space, 0);

    layout.addView(usernameEditText);
    layout.addView(passwordEditText);
    layout.addView(emailEditText);

    builder.setView(layout);

    builder.setPositiveButton(getString(R.string.dialog_register_ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            return;
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });

    final AlertDialog dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            utilitiesRestClient = new UtilitiesRestClient(getActivity(),
                    SharedPreferencesWrapper.getServerAddress(), SharedPreferencesWrapper.getServerPort(),
                    SharedPreferencesWrapper.getWebserviceContextPath());

            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!AppUtils.checkInternetConnection(getActivity())) {
                        Log.d(TAG, "There is NO network connected!");
                        return;
                    }

                    usernameEditText.setError(null);
                    passwordEditText.setError(null);
                    emailEditText.setError(null);

                    if (StringUtils.isBlank(usernameEditText.getText().toString())) {
                        usernameEditText.setError(getString(R.string.dialog_register_field_required));
                        return;
                    }
                    if (StringUtils.isBlank(passwordEditText.getText().toString())) {
                        passwordEditText.setError(getString(R.string.dialog_register_field_required));
                        return;
                    }
                    if (StringUtils.isBlank(emailEditText.getText().toString())) {
                        emailEditText.setError(getString(R.string.dialog_register_field_required));
                        return;
                    }
                    if (!AppUtils.validateEmail(emailEditText.getText().toString())) {
                        emailEditText.setError(getString(R.string.dialog_register_email_not_valid));
                        return;
                    }

                    final User user = new User();
                    user.setUsername(usernameEditText.getText().toString());
                    user.setPassword(SecurityUtils.hashSHA512Base64(passwordEditText.getText().toString()));
                    user.setEmail(StringUtils.lowerCase(emailEditText.getText().toString()));
                    user.setAddress(new AddressData());

                    utilitiesRestClient.registerUser(user, new AsyncHttpResponseHandler() {

                        @Override
                        public void onFailure(Throwable error, String content) {
                            Log.d(TAG,
                                    "Registering user failed. [error= " + error + ", content=" + content + "]");
                            AppUtils.showCenteredToast(context, getString(R.string.dialog_register_failed),
                                    Toast.LENGTH_LONG);
                        }

                        @Override
                        public void onFinish() {
                            positiveButton.setEnabled(true);
                        }

                        @Override
                        public void onStart() {
                            Log.d(TAG, "Registering user: " + user.toString());
                            AppUtils.showCenteredToast(context, getString(R.string.dialog_register_in_progress),
                                    Toast.LENGTH_SHORT);
                            positiveButton.setEnabled(false);
                        }

                        @Override
                        public void onSuccess(int statusCode, String content) {
                            Log.d(TAG, "Registered user successfully.");
                            AppUtils.showCenteredToast(context, getString(R.string.dialog_register_successful),
                                    Toast.LENGTH_SHORT);

                            SharedPreferencesWrapper.setUsername(user.getUsername());
                            SharedPreferencesWrapper.setPasswordHash(user.getPassword());
                            SharedPreferencesWrapper.setRememberUser(true);

                            dialog.dismiss();
                        }

                    });

                }
            });

            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    cancelRequests();
                    dialog.dismiss();
                }
            });

        }
    });

    return dialog;
}

From source file:org.bdigi.andy.MainActivity.java

private Fragment[] getModeFragments() {

    final Context ctx = MainActivity.this;

    Mode modes[] = getModes();/*ww w.j av  a  2  s .  c o  m*/
    Fragment frags[] = new Fragment[modes.length];
    for (int i = 0; i < modes.length; i++) {
        final Mode mode = modes[i];
        Fragment frag = new Fragment() {

            @Override
            public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
                LinearLayout layout = new LinearLayout(ctx);
                layout.setOrientation(LinearLayout.VERTICAL);
                TextView title = new TextView(ctx);
                title.setClickable(true);
                title.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        setMode(mode);
                    }
                });
                title.setText("Mode: " + mode.name());
                title.setTextAppearance(ctx, R.style.Title);
                layout.addView(title);

                Seq<Property<?>> props = mode.properties().properties();

                for (int i = 0; i < props.size(); i++) {
                    Property p = props.apply(i);

                    if (p instanceof BooleanProperty) {
                        layout.addView(new PropWidget.BooleanPropertyWidget(ctx, (BooleanProperty) p));
                    } else if (p instanceof RadioProperty) {
                        layout.addView(new PropWidget.RadioPropertyWidget(ctx, (RadioProperty) p));
                    }
                }
                return layout;
            }
        };
        frags[i] = frag;
    }
    return frags;
}

From source file:org.onebusaway.android.ui.ListFragment.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.
 *
 * <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.
 *///from  w  w w.  j a  va  2 s.  c o  m
@Override
@SuppressWarnings("deprecation")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

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

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

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    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(R.id.listContainer);

    TextView tv = new TextView(getActivity());
    tv.setId(R.id.internalEmpty);
    tv.setGravity(Gravity.CENTER);
    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:edu.byu.scriptures.controller.fragment.RestartableRecyclerFragment.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.
 *
 * <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.
 *///from  w ww  .  j  a v  a  2s .  c om
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    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.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_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.setTextSize(18);

    int padding = ((MainActivity) getActivity()).getMetricsManager().dpToRawPixels(20);

    tv.setPadding(padding, 0, padding, 0);
    tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_normal));
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    RecyclerView recyclerView = new RecyclerView(getActivity());
    recyclerView.setId(android.R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    //        lv.setDrawSelectorOnTop(false);
    lframe.addView(recyclerView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

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

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

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

    return root;
}

From source file:com.umeng.comm.ui.emoji.EmojiBorad.java

/**
 * </br>//w w w.  jav  a 2  s  .  c  o m
 * 
 * @return
 */
private ViewGroup createPointLinearlayout() {
    LinearLayout pointContainerLayout = new LinearLayout(getContext());
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    pointContainerLayout.setLayoutParams(params);
    pointContainerLayout.setOrientation(LinearLayout.HORIZONTAL);
    pointContainerLayout.setGravity(Gravity.CENTER);
    params.gravity = Gravity.CENTER;
    params.topMargin = DeviceUtils.dp2px(getContext(), 15);
    params.bottomMargin = DeviceUtils.dp2px(getContext(), 15);
    return pointContainerLayout;
}

From source file:eu.geopaparazzi.library.forms.views.GTimeView.java

/**
 * @param fragment the fragment.//ww  w  .  ja  v a2  s .co  m
 * @param attrs attributes.
 * @param parentView parent
 * @param key key
 * @param value value
 * @param constraintDescription constraints
 * @param readonly if <code>false</code>, the item is disabled for editing.
 */
public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value,
        String constraintDescription, boolean readonly) {
    super(fragment.getActivity(), attrs);

    Context context = fragment.getActivity();

    LinearLayout textLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(context);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(context.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    button = new Button(context);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);

    final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER;
    if (value == null || value.length() == 0) {
        String dateStr = timeFormatter.format(new Date());
        button.setText(dateStr);
    } else {
        button.setText(value);
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String dateStr = button.getText().toString();
            Date date = null;
            try {
                date = timeFormatter.parse(dateStr);
            } catch (ParseException e) {
                // fallback on current date
                date = new Date();
            }
            final Calendar c = Calendar.getInstance();
            c.setTime(date);
            int hourOfDay = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            FormTimePickerFragment newFragment = new FormTimePickerFragment();
            newFragment.setAttributes(hourOfDay, minute, true, button);
            newFragment.show(fragment.getFragmentManager(), "timePicker");
        }
    });
    button.setEnabled(!readonly);

    textLayout.addView(button);
}

From source file:com.yahala.ui.Views.EmojiViewExtra.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    loadRecents();//from  w  w  w  .  j  ava2  s. c om
    setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
            Color.parseColor("#FF373737"), Color.parseColor("#FF575757"), Color.parseColor("#FF666666") }));

    emojiPagerAdapter = new EmojiPagerAdapter(getContext(), EmojiManager.getInstance().categories);
    pager = new ViewPager(getContext());
    pager.setOffscreenPageLimit(5);
    pager.setAdapter(emojiPagerAdapter);
    FileLog.e("EmojiManager.emojiGroups", "" + EmojiManager.getInstance().categories.size());
    PagerSlidingTabStripEmoji tabs = new PagerSlidingTabStripEmoji(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(false);
    tabs.setMinimumWidth(OSUtilities.dp(50));
    tabs.setTabPaddingLeftRight(OSUtilities.dp(10));
    tabs.setIndicatorHeight(3);
    //tabs.setTabBackground(Color.parseColor("#FF3f9fe0"));
    tabs.setTabBackground(R.drawable.bar_selector_main);

    tabs.setIndicatorColor(Color.parseColor("#FFffffff"));
    tabs.setDividerColor(Color.parseColor("#ff222222"));
    tabs.setUnderlineHeight(2);
    tabs.setUnderlineColor(Color.parseColor("#ff373737"));

    //tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (EmojiViewExtra.this.listener != null) {
                EmojiViewExtra.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LayoutParams(OSUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    /* recentsWrap = new FrameLayout(getContext());
     recentsWrap.addView(views.get(0));
     TextView localTextView = new TextView(getContext());
     localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
     localTextView.setTextSize(18.0f);
     localTextView.setTextColor(-7829368);
     localTextView.setGravity(17);
     recentsWrap.addView(localTextView);
     views.get(0).setEmptyView(localTextView);*/
    addView(localLinearLayout, new LayoutParams(-1, OSUtilities.dpf(48.0f)));

    addView(pager);

    if (!EmojiManager.getInstance().categoriesDict.containsKey("recents")
            || EmojiManager.getInstance().categoriesDict.get("recents").emojis.size() == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:eu.geopaparazzi.library.forms.views.GDateView.java

/**
 * @param fragment   the fragment to use.
 * @param attrs attributes./*from w w w . ja v a2  s.  c  o  m*/
 * @param parentView parent
 * @param key key
 * @param value value
 * @param constraintDescription constraints
 * @param readonly if <code>false</code>, the item is disabled for editing.
 */
public GDateView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value,
        String constraintDescription, boolean readonly) {
    super(fragment.getActivity(), attrs);

    Context context = fragment.getActivity();

    LinearLayout textLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(context);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(context.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    button = new Button(context);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);

    final SimpleDateFormat dateFormatter = TimeUtilities.INSTANCE.DATEONLY_FORMATTER;
    if (value == null || value.length() == 0) {
        String dateStr = dateFormatter.format(new Date());
        button.setText(dateStr);
    } else {
        button.setText(value);
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String dateStr = button.getText().toString();
            Date date = null;
            try {
                date = dateFormatter.parse(dateStr);
            } catch (ParseException e) {
                // fallback on current date
                date = new Date();
            }
            final Calendar c = Calendar.getInstance();
            c.setTime(date);
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            FormDatePickerFragment newFragment = new FormDatePickerFragment(year, month, day, button);
            newFragment.show(fragment.getFragmentManager(), "datePicker");
        }
    });
    button.setEnabled(!readonly);

    textLayout.addView(button);
}

From source file:com.citrus.sample.UIActivity.java

private void promptAutoLoadSubscription() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(UIActivity.this);
    String message = null;//from   w w w  .j av  a2s . c o  m
    String positiveButtonText = "Yes";

    LinearLayout linearLayout = new LinearLayout(UIActivity.this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    alert.setTitle("Enable Auto-Load?");
    alert.setMessage(getString(R.string.auto_load_message));

    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
                    .setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
                    .replace(R.id.container, AutoLoadFragment.newInstance());
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    });

    alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });
    alert.show();
}

From source file:org.yasik.android.app.GridFragment.java

/**
 * Provide default implementation to return a simple grid view. Subclasses can
 * override to replace with their own layout. If doing so, the returned view
 * hierarchy <em>must</em> have a GridView 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.// w ww  .  ja  v  a2s . com
 *
 * <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
 * GridFragment. In particular, this is currently the only way to have the
 * built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    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.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_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);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

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

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

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

    return root;
}