Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

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

Prototype

public TextView(Context context) 

Source Link

Usage

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

/**
 * Create or recreate the limiter breadcrumbs.
 *//*www. ja  v  a 2  s .  c o  m*/
public void updateLimiterViews() {
    mLimiterViews.removeAllViews();

    Limiter limiterData = mPagerAdapter.getCurrentLimiter();
    if (limiterData != null) {
        String[] limiter = limiterData.names;

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        params.leftMargin = 5;
        for (int i = 0; i != limiter.length; ++i) {
            PaintDrawable background = new PaintDrawable(Color.GRAY);
            background.setCornerRadius(5);

            TextView view = new TextView(this);
            view.setSingleLine();
            view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
            view.setText(limiter[i] + " | X");
            view.setTextColor(Color.WHITE);
            view.setBackgroundDrawable(background);
            view.setLayoutParams(params);
            view.setPadding(5, 2, 5, 2);
            view.setTag(i);
            view.setOnClickListener(this);
            mLimiterViews.addView(view);
        }

        mLimiterScroller.setVisibility(View.VISIBLE);
    } else {
        mLimiterScroller.setVisibility(View.GONE);
    }
}

From source file:com.facebook.android.friendsmash.ScoreboardFragment.java

private void populateScoreboard() {
    // Ensure all components are firstly removed from scoreboardContainer
    scoreboardContainer.removeAllViews();

    // Ensure the progress spinner is hidden
    progressContainer.setVisibility(View.INVISIBLE);

    // Ensure scoreboardEntriesList is not null and not empty first
    if (application.getScoreboardEntriesList() == null || application.getScoreboardEntriesList().size() <= 0) {
        closeAndShowError(getResources().getString(R.string.error_no_scores));
    } else {//from www .  jav  a2  s . co m
        // Iterate through scoreboardEntriesList, creating new UI elements for each entry
        int index = 0;
        Iterator<ScoreboardEntry> scoreboardEntriesIterator = application.getScoreboardEntriesList().iterator();
        while (scoreboardEntriesIterator.hasNext()) {
            // Get the current scoreboard entry
            final ScoreboardEntry currentScoreboardEntry = scoreboardEntriesIterator.next();

            // FrameLayout Container for the currentScoreboardEntry ...

            // Create and add a new FrameLayout to display the details of this entry
            FrameLayout frameLayout = new FrameLayout(getActivity());
            scoreboardContainer.addView(frameLayout);

            // Set the attributes for this frameLayout
            int topPadding = getResources().getDimensionPixelSize(R.dimen.scoreboard_entry_top_margin);
            frameLayout.setPadding(0, topPadding, 0, 0);

            // ImageView background image ...
            {
                // Create and add an ImageView for the background image to this entry
                ImageView backgroundImageView = new ImageView(getActivity());
                frameLayout.addView(backgroundImageView);

                // Set the image of the backgroundImageView
                String uri = "drawable/scores_stub_even";
                if (index % 2 != 0) {
                    // Odd entry
                    uri = "drawable/scores_stub_odd";
                }
                int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName());
                Drawable image = getResources().getDrawable(imageResource);
                backgroundImageView.setImageDrawable(image);

                // Other attributes of backgroundImageView to modify
                FrameLayout.LayoutParams backgroundImageViewLayoutParams = new FrameLayout.LayoutParams(
                        FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
                int backgroundImageViewMarginTop = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_background_imageview_margin_top);
                backgroundImageViewLayoutParams.setMargins(0, backgroundImageViewMarginTop, 0, 0);
                backgroundImageViewLayoutParams.gravity = Gravity.LEFT;
                if (index % 2 != 0) {
                    // Odd entry
                    backgroundImageViewLayoutParams.gravity = Gravity.RIGHT;
                }
                backgroundImageView.setLayoutParams(backgroundImageViewLayoutParams);
            }

            // ProfilePictureView of the current user ...
            {
                // Create and add a ProfilePictureView for the current user entry's profile picture
                ProfilePictureView profilePictureView = new ProfilePictureView(getActivity());
                frameLayout.addView(profilePictureView);

                // Set the attributes of the profilePictureView
                int profilePictureViewWidth = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_width);
                FrameLayout.LayoutParams profilePictureViewLayoutParams = new FrameLayout.LayoutParams(
                        profilePictureViewWidth, profilePictureViewWidth);
                int profilePictureViewMarginLeft = 0;
                int profilePictureViewMarginTop = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_top);
                int profilePictureViewMarginRight = 0;
                int profilePictureViewMarginBottom = 0;
                if (index % 2 == 0) {
                    profilePictureViewMarginLeft = getResources()
                            .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_left);
                } else {
                    profilePictureViewMarginRight = getResources()
                            .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_right);
                }
                profilePictureViewLayoutParams.setMargins(profilePictureViewMarginLeft,
                        profilePictureViewMarginTop, profilePictureViewMarginRight,
                        profilePictureViewMarginBottom);
                profilePictureViewLayoutParams.gravity = Gravity.LEFT;
                if (index % 2 != 0) {
                    // Odd entry
                    profilePictureViewLayoutParams.gravity = Gravity.RIGHT;
                }
                profilePictureView.setLayoutParams(profilePictureViewLayoutParams);

                // Finally set the id of the user to show their profile pic
                profilePictureView.setProfileId(currentScoreboardEntry.getId());
            }

            // LinearLayout to hold the text in this entry

            // Create and add a LinearLayout to hold the TextViews
            LinearLayout textViewsLinearLayout = new LinearLayout(getActivity());
            frameLayout.addView(textViewsLinearLayout);

            // Set the attributes for this textViewsLinearLayout
            FrameLayout.LayoutParams textViewsLinearLayoutLayoutParams = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            int textViewsLinearLayoutMarginLeft = 0;
            int textViewsLinearLayoutMarginTop = getResources()
                    .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_top);
            int textViewsLinearLayoutMarginRight = 0;
            int textViewsLinearLayoutMarginBottom = 0;
            if (index % 2 == 0) {
                textViewsLinearLayoutMarginLeft = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_left);
            } else {
                textViewsLinearLayoutMarginRight = getResources()
                        .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_right);
            }
            textViewsLinearLayoutLayoutParams.setMargins(textViewsLinearLayoutMarginLeft,
                    textViewsLinearLayoutMarginTop, textViewsLinearLayoutMarginRight,
                    textViewsLinearLayoutMarginBottom);
            textViewsLinearLayoutLayoutParams.gravity = Gravity.LEFT;
            if (index % 2 != 0) {
                // Odd entry
                textViewsLinearLayoutLayoutParams.gravity = Gravity.RIGHT;
            }
            textViewsLinearLayout.setLayoutParams(textViewsLinearLayoutLayoutParams);
            textViewsLinearLayout.setOrientation(LinearLayout.VERTICAL);

            // TextView with the position and name of the current user
            {
                // Set the text that should go in this TextView first
                int position = index + 1;
                String currentScoreboardEntryTitle = position + ". " + currentScoreboardEntry.getName();

                // Create and add a TextView for the current user position and first name
                TextView titleTextView = new TextView(getActivity());
                textViewsLinearLayout.addView(titleTextView);

                // Set the text and other attributes for this TextView
                titleTextView.setText(currentScoreboardEntryTitle);
                titleTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerNameFont);
            }

            // TextView with the score of the current user
            {
                // Create and add a TextView for the current user score
                TextView scoreTextView = new TextView(getActivity());
                textViewsLinearLayout.addView(scoreTextView);

                // Set the text and other attributes for this TextView
                scoreTextView.setText("Score: " + currentScoreboardEntry.getScore());
                scoreTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerScoreFont);
            }

            // Finally make this frameLayout clickable so that a game starts with the user smashing
            // the user represented by this frameLayout in the scoreContainer
            frameLayout.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        Bundle bundle = new Bundle();
                        bundle.putString("user_id", currentScoreboardEntry.getId());

                        Intent i = new Intent();
                        i.putExtras(bundle);

                        getActivity().setResult(Activity.RESULT_FIRST_USER, i);
                        getActivity().finish();
                        return false;
                    } else {
                        return true;
                    }
                }

            });

            // Increment the index before looping back
            index++;
        }
    }
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public void onClick(View view) {
    if (view == btnGoBack) {
        if (isAtFavorites) {
            isAtFavorites = false;//from   w  w  w. ja v a 2s.  c o m
            doSearch();
        } else {
            finish(0, view, true);
        }
    } else if (view == btnFavorite) {
        isAtFavorites = true;
        radioStationList.cancel();
        radioStationList.fetchFavorites(getApplication());
        updateButtons();
    } else if (view == btnSearch) {
        final Context ctx = getHostActivity();
        final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        chkGenre = new RadioButton(ctx);
        chkGenre.setText(R.string.genre);
        chkGenre.setChecked(Player.lastRadioSearchWasByGenre);
        chkGenre.setOnClickListener(this);
        chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        btnGenre = new Spinner(ctx);
        btnGenre.setContentDescription(ctx.getText(R.string.genre));
        btnGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad << 1;
        chkTerm = new RadioButton(ctx);
        chkTerm.setText(R.string.search_term);
        chkTerm.setChecked(!Player.lastRadioSearchWasByGenre);
        chkTerm.setOnClickListener(this);
        chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        txtTerm = new EditText(ctx);
        txtTerm.setContentDescription(ctx.getText(R.string.search_term));
        txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm);
        txtTerm.setOnClickListener(this);
        txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        txtTerm.setSingleLine();
        txtTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        p.bottomMargin = UI._DLGsppad;
        final TextView lbl = new TextView(ctx);
        lbl.setAutoLinkMask(0);
        lbl.setLinksClickable(true);
        //http://developer.android.com/design/style/color.html
        lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5));
        lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp);
        lbl.setGravity(Gravity.CENTER_HORIZONTAL);
        lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org)));
        lbl.setMovementMethod(LinkMovementMethod.getInstance());
        lbl.setLayoutParams(p);

        l.addView(chkGenre);
        l.addView(btnGenre);
        l.addView(chkTerm);
        l.addView(txtTerm);
        l.addView(lbl);

        btnGenre.setAdapter(this);
        btnGenre.setSelection(getValidGenre(Player.radioLastGenre));
        defaultTextColors = txtTerm.getTextColors();

        UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l)
                .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this)
                .setOnCancelListener(this).create());
    } else if (view == btnGoBackToPlayer) {
        finish(-1, view, false);
    } else if (view == btnAdd) {
        addPlaySelectedItem(false);
    } else if (view == btnPlay) {
        addPlaySelectedItem(true);
    } else if (view == chkGenre || view == btnGenre) {
        chkGenre.setChecked(true);
        chkTerm.setChecked(false);
    } else if (view == chkTerm || view == txtTerm) {
        chkGenre.setChecked(false);
        chkTerm.setChecked(true);
    } else if (view == list) {
        if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0))
            onClick(btnFavorite);
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEvent.java

private void AddLogMessage(final String Message) {
    addMessageProgressDialog = new ProgressDialog(this);
    addMessageProgressDialog.setTitle("Contacting Zenoss");
    addMessageProgressDialog.setMessage("Please wait:\nProcessing Event Log Updates");
    addMessageProgressDialog.show();/*from w  w w .j  av  a  2s  . c om*/

    addLogMessageHandler = new Handler() {
        public void handleMessage(Message msg) {
            addMessageProgressDialog.dismiss();

            if (msg.what == 1) {
                try {
                    /*String[] tmp = LogEntries.clone();
                    final int NewArrlength = tmp.length + 1;
                    LogEntries = new String[NewArrlength];
                            
                    LogEntries[0] = settings.getString("userName", "") + " wrote " + Message + "\nAt: Just now";*/

                    /*for (int i = 1; i < NewArrlength; ++i) //
                    {
                       LogEntries[i] = tmp[(i -1)];
                    }
                    tmp = null;//help out the GC
                          ((ListView) findViewById(R.id.LogList)).setAdapter(new ArrayAdapter<String>(ViewZenossEvent.this, R.layout.search_simple,LogEntries));*/

                    TextView newLog = new TextView(ViewZenossEvent.this);
                    newLog.setText(Html.fromHtml("<strong>" + settings.getString("userName", "")
                            + "</strong> wrote " + Message + "\n<br/><strong>At:</strong> Just now"));
                    newLog.setPadding(0, 6, 0, 6);
                    ((LinearLayout) findViewById(R.id.LogList)).addView(newLog);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddMessageProgressHandler", e);
                    Toast.makeText(ViewZenossEvent.this,
                            "The log message was successfully sent to Zenoss but an error occured when updating the UI",
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(ViewZenossEvent.this, "An error was encountered adding your message to the log",
                        Toast.LENGTH_LONG).show();
            }

        }
    };

    addLogMessageThread = new Thread() {
        public void run() {
            Boolean Success = false;

            try {
                if (API == null) {
                    if (settings.getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) {
                        API = new ZenossAPIZaas();
                    } else {
                        API = new ZenossAPICore();
                    }
                    ZenossCredentials credentials = new ZenossCredentials(ViewZenossEvent.this);
                    API.Login(credentials);
                }

                Success = API.AddEventLog(getIntent().getStringExtra("EventID"), Message);
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEvent", "AddLogMessageThread", e);
                addLogMessageHandler.sendEmptyMessage(0);
            }

            if (Success) {
                addLogMessageHandler.sendEmptyMessage(1);
            } else {
                addLogMessageHandler.sendEmptyMessage(0);
            }
        }
    };

    addLogMessageThread.start();
}

From source file:com.bionx.res.DashMainActivity.java

@SuppressWarnings("deprecation")
@Override// www. j a v a  2s  . co  m
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 11:
        // Create our About Dialog
        TextView aboutMsg = new TextView(this);
        aboutMsg.setMovementMethod(LinkMovementMethod.getInstance());
        aboutMsg.setPadding(30, 30, 30, 30);
        aboutMsg.setText(Html.fromHtml(
                "To view more information about the development of the Bionx Dashboard, Continue into the Information Center, If you don't care much for license and authors, click 'Proceed'."));

        Builder builder = new AlertDialog.Builder(this);
        builder.setView(aboutMsg)
                .setTitle(Html.fromHtml("Dashboard <b><font color='"
                        + getResources().getColor(R.color.holo_blue) + "'>Info</font></b>"))
                .setIcon(R.drawable.ic_launcher).setCancelable(true)
                .setPositiveButton("Information Drawer", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent dialog_intent = new Intent(getBaseContext(), InformationDrawer.class);
                        startActivity(dialog_intent);
                    }
                }).setNegativeButton("Proceed", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(), "Bionx Dashboard", Toast.LENGTH_LONG).show();
                    }
                });
        return builder.create();
    }
    return super.onCreateDialog(id);
}

From source file:com.sft.blackcatapp.EnrollSchoolActivity.java

private void setViewPager() {
    InfinitePagerAdapter adapter = null;
    int length = 0;
    if (adImageUrl != null && adImageUrl.length > 0) {
        adapter = new InfinitePagerAdapter(this, adImageUrl, screenWidth, viewPagerHeight);
        length = adImageUrl.length;/*from w  ww  .  j a  v a2  s  . c o m*/
    } else {
        adapter = new InfinitePagerAdapter(this, new int[] { R.drawable.defaultimage });
        length = 1;
        defaultImage.setVisibility(View.GONE);
    }
    adapter.setPageClickListener(new MyPageClickListener());
    adapter.setURLErrorListener(this);
    topViewPager.setAdapter(adapter);

    imageViews = new ImageView[length];
    ImageView imageView = null;
    dotLayout.removeAllViews();
    LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams((int) (8 * screenDensity),
            (int) (4 * screenDensity));
    dotLayout.addView(new TextView(this), textParams);
    // ?
    for (int i = 0; i < length; i++) {
        imageView = new ImageView(this);
        // ?imageview?
        imageView.setLayoutParams(new LayoutParams((int) (6 * screenDensity), (int) (6 * screenDensity)));// ?20
        // 
        // ?layout
        imageView.setBackgroundResource(R.drawable.enroll_school_dot_selector);
        imageViews[i] = imageView;

        // ???
        if (i == 0) {
            imageView.setEnabled(true);
        } else {
            imageView.setEnabled(false);
        }
        // imageviews?
        dotLayout.addView(imageViews[i]);
        dotLayout.addView(new TextView(this), textParams);
    }
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

/**
 * Create or recreate the limiter breadcrumbs.
 *///  w  w  w  .ja v  a  2  s  . c  o m
public void updateLimiterViews() {
    mLimiterViews.removeAllViews();

    Limiter limiterData = mPagerAdapter.getCurrentLimiter();
    if (limiterData != null) {
        String[] limiter = limiterData.names;

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        params.leftMargin = 5;
        for (int i = 0; i != limiter.length; ++i) {
            int color = (i + 1 == limiter.length ? 0xFFA0A0A0 : 0xFFC0C0C0);
            PaintDrawable background = new PaintDrawable(color);
            background.setCornerRadius(0);

            TextView view = new TextView(this);
            view.setSingleLine();
            view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
            view.setText(limiter[i]);
            view.setTextColor(Color.WHITE);
            view.setBackgroundDrawable(background);
            view.setLayoutParams(params);
            view.setPadding(14, 6, 14, 6);
            view.setTag(i);
            view.setOnClickListener(this);
            mLimiterViews.addView(view);
        }

        mLimiterScroller.setVisibility(View.VISIBLE);
    } else {
        mLimiterScroller.setVisibility(View.GONE);
    }
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

private ArrayAdapter<String> popupMenuAdapter(String itemTagArray[]) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            itemTagArray) {// w  ww.ja  v  a 2 s  .co m
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // setting the ID and text for every items in the list
            String item = getItem(position);
            String[] itemArr = item.split("::");
            String text = itemArr[0];
            String id = itemArr[1];

            // visual settings for the list item
            TextView listItem = new TextView(AnalyzeActivity.this);

            if (id.equals("0")) {
                listItem.setText(text);
                listItem.setTag(id);
                listItem.setTextSize(listItemTitleTextSize / DPRatio);
                listItem.setPadding(5, 5, 5, 5);
                listItem.setTextColor(Color.GREEN);
                listItem.setGravity(android.view.Gravity.CENTER);
            } else {
                listItem.setText(text);
                listItem.setTag(id);
                listItem.setTextSize(listItemTextSize / DPRatio);
                listItem.setPadding(5, 5, 5, 5);
                listItem.setTextColor(Color.WHITE);
                listItem.setGravity(android.view.Gravity.CENTER);
            }

            return listItem;
        }
    };
    return adapter;
}

From source file:com.photon.phresco.nativeapp.eshop.activity.ProductDetailActivity.java

/**
 * Create the details sections at the bottom of the screen dynamically
 *
 * @param details/*from  w  ww  .j  a  v  a  2  s  . c  om*/
 * @throws NumberFormatException
 */
private void renderProdcutDetails(Map<String, String> details) {

    try {
        LinearLayout tl = (LinearLayout) findViewById(R.id.product_details_layout);
        int totalDetails = details.size();
        int cnt = 1;
        PhrescoLogger.info(TAG + "renderProdcutDetails() - totalDetails : " + totalDetails);
        TextView lblDetailLabel = null;
        for (Entry<String, String> entry : details.entrySet()) {

            // Create a TextView to hold the label for product detail
            lblDetailLabel = new TextView(this);
            if (cnt == 1) {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_top);
            } else if (cnt == totalDetails) {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_bottom);
            } else {
                lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_middle);
            }
            lblDetailLabel.setText(entry.getKey() + ": " + entry.getValue());
            lblDetailLabel.setGravity(Gravity.CENTER);
            lblDetailLabel.setTypeface(Typeface.DEFAULT, style.TextViewStyle);
            lblDetailLabel.setTextColor(Color.WHITE);
            lblDetailLabel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f));
            tl.addView(lblDetailLabel);
            cnt++;
        }
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "renderProdcutDetails - Exception : " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * Creates the auto layout.//  w w w . ja v a  2  s . c  o m
 * It contains toggle button to switch auto state, two text view to indicate auto messages.
 * 
 * @return the relative layout
 */
private RelativeLayout createAutoLayout() {
    RelativeLayout autoLayout = new RelativeLayout(this);
    autoLayout.setPadding(10, 5, 10, 10);
    autoLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 80));
    TextView autoText = new TextView(this);
    RelativeLayout.LayoutParams autoTextLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    autoTextLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    autoTextLayout.addRule(RelativeLayout.CENTER_VERTICAL);
    autoText.setLayoutParams(autoTextLayout);
    autoText.setText("Auto Discovery");

    ToggleButton autoButton = new ToggleButton(this);
    autoButton.setWidth(150);
    RelativeLayout.LayoutParams autoButtonLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    autoButtonLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    autoButtonLayout.addRule(RelativeLayout.CENTER_VERTICAL);
    autoButton.setLayoutParams(autoButtonLayout);
    autoButton.setChecked(autoMode);
    autoButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            appSettingsView.removeViewAt(2);
            currentServer = "";
            if (isChecked) {
                IPAutoDiscoveryServer.isInterrupted = false;
                appSettingsView.addView(constructAutoServersView(), 2);
            } else {
                IPAutoDiscoveryServer.isInterrupted = true;
                appSettingsView.addView(constructCustomServersView(), 2);
            }
            AppSettingsModel.setAutoMode(AppSettingsActivity.this, isChecked);
        }
    });

    TextView infoText = new TextView(this);
    RelativeLayout.LayoutParams infoTextLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    infoTextLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    infoTextLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    infoText.setLayoutParams(infoTextLayout);
    infoText.setTextSize(10);
    infoText.setText("Turn off auto-discovery to input controller url manually.");

    autoLayout.addView(autoText);
    autoLayout.addView(autoButton);
    autoLayout.addView(infoText);
    return autoLayout;
}