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:fr.cph.chicago.adapter.SearchAdapter.java

@Override
public final View getView(final int position, View convertView, final ViewGroup parent) {

    LayoutInflater vi = (LayoutInflater) ChicagoTracker.getAppContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = vi.inflate(R.layout.list_search, null);

    TextView rounteName = (TextView) convertView.findViewById(R.id.station_name);

    if (position < mTrains.size()) {
        final Station station = (Station) getItem(position);
        Set<TrainLine> lines = station.getLines();

        rounteName.setText(station.getName());

        LinearLayout stationColorView = (LinearLayout) convertView.findViewById(R.id.station_color);

        int indice = 0;
        for (TrainLine tl : lines) {
            TextView textView = new TextView(mContext);
            textView.setBackgroundColor(tl.getColor());
            textView.setText(" ");
            textView.setTextSize(mContext.getResources().getDimension(R.dimen.activity_list_station_colors));
            stationColorView.addView(textView);
            if (indice != lines.size()) {
                textView = new TextView(mContext);
                textView.setText("");
                textView.setPadding(0, 0,
                        (int) mContext.getResources().getDimension(R.dimen.activity_list_station_colors_space),
                        0);//  w ww .  j  a v  a2s . c o m
                textView.setTextSize(
                        mContext.getResources().getDimension(R.dimen.activity_list_station_colors));
                stationColorView.addView(textView);
            }
            indice++;
        }
        convertView.setOnClickListener(
                new FavoritesTrainOnClickListener(mActivity, mContainer, station.getId(), lines));
    } else if (position < mTrains.size() + mBuses.size()) {
        final BusRoute busRoute = (BusRoute) getItem(position);

        TextView type = (TextView) convertView.findViewById(R.id.train_bus_type);
        type.setText("B");

        rounteName.setText(busRoute.getId() + " " + busRoute.getName());

        final TextView loadingTextView = (TextView) convertView.findViewById(R.id.loading_text_view);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadingTextView.setVisibility(LinearLayout.VISIBLE);
                mActivity.startRefreshAnimation();
                new DirectionAsyncTask().execute(busRoute, loadingTextView);
            }
        });
    } else {
        final BikeStation bikeStation = (BikeStation) getItem(position);

        TextView type = (TextView) convertView.findViewById(R.id.train_bus_type);
        type.setText("D");

        rounteName.setText(bikeStation.getName());

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChicagoTracker.getAppContext(), BikeStationActivity.class);
                Bundle extras = new Bundle();
                extras.putParcelable("station", bikeStation);
                intent.putExtras(extras);
                mActivity.startActivity(intent);
                mActivity.overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
            }
        });
    }

    return convertView;
}

From source file:com.cyanogenmod.eleven.widgets.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);//from   w w w.  j a  v a2  s  .  co m
    textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.chenupt.springindicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<TextView>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null) {
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        }/* ww  w.  jav  a2s. c o  m*/
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0) {
            textView.setBackgroundResource(textBgResId);
        }
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.chalilayang.test.customview.springindicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null) {
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        }/*  w w w  . j a  va  2 s.  c  o  m*/
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0) {
            textView.setBackgroundResource(textBgResId);
        }
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:android.view.SpringIndicator.java

private void addTabItems() {
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        final TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null)
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0)
            textView.setBackgroundResource(textBgResId);
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override/* w  w  w.j  av  a2s .com*/
            public void onClick(final View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position))
                    viewPager.setCurrentItem(position);
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.android.firewall.FirewallListPage.java

private TextView getTabView(int width, int height, String title) {
    TextView view = new TextView(this);
    view.setMinimumWidth(width);// www. ja va  2s  .c o  m
    view.setMinimumHeight(height);
    view.setGravity(Gravity.CENTER);
    view.setBackgroundResource(R.drawable.tab_indicator_holo);
    view.setText(title);
    return view;
}

From source file:com.cheikh.lazywaimai.widget.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from  w w w.j ava  2 s  .  c om
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return textView;
}

From source file:com.nextgis.mobile.map.RemoteTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName,
        String layerUrl, int type, final RemoteTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);/*from w w w  .  j a  v a  2  s. c  om*/

    final EditText url = new EditText(map.getContext());
    url.setText(layerUrl);

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerUrl = new TextView(map.getContext());
    stLayerUrl.setText(map.getContext().getString(R.string.layer_url) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(0);
    } else {
        spinner.setSelection(1);
    }

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerUrl);
    linearLayout.addView(url);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), url.getText().toString(), tmsType);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:at.wada811.app.fragment.ExpandableListFragment.java

/**
 * Provide default implementation to return a expandable list view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a ExpandableListView 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./*  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 ExpandableListFragment. In particular,
 * this is currently the only way to have the built-in indeterminant progress state be shown.
 * 
 * @param inflater The LayoutInflater object that can be used to inflate any views in the
 *        fragment,
 * @param container If non-null, this is the parent view that the fragment's UI should be
 *        attached to. The fragment should not add the view itself, but this can be used to
 *        generate the LayoutParams of the view.
 * @param savedInstanceState If non-null, this fragment is being re-constructed from a previous
 *        saved state as given here.
 * @return Return the View for the fragment's UI, or null.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

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

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

    final 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));

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

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

    final 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));

    final ExpandableListView lv = new ExpandableListView(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;
}

From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java

public void addTextItem(String text) {
    TextView view = new TextView(getContext());
    view.setText(text);//from www .j  a v a 2s  .c  o  m
    view.setBackgroundResource(R.drawable.item_background);
    view.setTextColor(ContextCompat.getColorStateList(getContext(), R.color.bigbang_item_text));
    view.setGravity(Gravity.CENTER);
    if (mItemTextSize > 0)
        view.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemTextSize);
    addView(view);
}