Example usage for android.widget TextView setId

List of usage examples for android.widget TextView setId

Introduction

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

Prototype

public void setId(@IdRes int id) 

Source Link

Document

Sets the identifier for this view.

Usage

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBikes(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    final int index = position - (stations.size() + busStops.size());
    final BikeStation bikeStation = bikeStations.get(index);

    final LinearLayout favoritesData = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(/*from   www  . j av a2s.  c  o m*/
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bike_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(bikeStation.getName());

    final LinearLayout llh = new LinearLayout(context);
    llh.setOrientation(LinearLayout.HORIZONTAL);
    llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0);

    final LinearLayout availableLayout = new LinearLayout(context);
    availableLayout.setOrientation(LinearLayout.VERTICAL);

    final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableBikes = new RelativeLayout(context);
    availableBikes.setLayoutParams(leftParam);
    availableBikes.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId = Util.generateViewId();
    lineIndication.setId(lineId);

    final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
    availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableBike = new TextView(context);
    availableBike.setText(context.getString(R.string.bike_available_bikes));
    availableBike.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableBike.setLayoutParams(availableParam);
    int availableBikeId = Util.generateViewId();
    availableBike.setId(availableBikeId);

    final RelativeLayout.LayoutParams amountParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam.addRule(RelativeLayout.RIGHT_OF, availableBikeId);

    final TextView amountBike = new TextView(context);
    final String amountBikeText = String.valueOf(bikeStation.getAvailableBikes());
    amountBike.setText(amountBikeText);
    int color = bikeStation.getAvailableBikes() == 0 ? R.color.red : R.color.green;
    amountBike.setTextColor(ContextCompat.getColor(context, color));
    amountBike.setLayoutParams(amountParam);

    availableBikes.addView(lineIndication);
    availableBikes.addView(availableBike);
    availableBikes.addView(amountBike);

    final LinearLayout.LayoutParams leftParam2 = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableDocks = new RelativeLayout(context);
    availableDocks.setLayoutParams(leftParam2);
    availableDocks.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication2 = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId2 = Util.generateViewId();
    lineIndication2.setId(lineId2);

    final RelativeLayout.LayoutParams availableDockParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableDockParam.addRule(RelativeLayout.RIGHT_OF, lineId2);
    availableDockParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableDock = new TextView(context);
    availableDock.setText(context.getString(R.string.bike_available_docks));
    availableDock.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableDock.setLayoutParams(availableDockParam);
    int availableDockBikeId = Util.generateViewId();
    availableDock.setId(availableDockBikeId);

    final RelativeLayout.LayoutParams amountParam2 = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam2.addRule(RelativeLayout.RIGHT_OF, availableDockBikeId);

    final TextView amountDock = new TextView(context);
    final String amountDockText = String.valueOf(bikeStation.getAvailableDocks());
    amountDock.setText(amountDockText);
    color = bikeStation.getAvailableDocks() == 0 ? R.color.red : R.color.green;
    amountDock.setTextColor(ContextCompat.getColor(context, color));

    amountDock.setLayoutParams(amountParam2);

    availableDocks.addView(lineIndication2);
    availableDocks.addView(availableDock);
    availableDocks.addView(amountDock);

    availableLayout.addView(availableBikes);
    availableLayout.addView(availableDocks);

    llh.addView(availableLayout);

    favoritesData.addView(llh);

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, bikeStation.getId(),
            bikeStation.getLatitude(), bikeStation.getLongitude()));
    return convertView;
}

From source file:com.example.fragmentdemo.views.PagerSlidingTabStrip.java

private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId,
        int iIconLocation) {
    // final View tabView = ((Activity) getContext()).getLayoutInflater()
    // .inflate(iLayoutResId, null);
    // TextView tab_text_textview = (TextView)
    // tabView.findViewById(iTextId);
    // tab_text_textview.setText(title);
    LinearLayout tabView = new LinearLayout(getContext());
    tabView.setGravity(Gravity.CENTER);/*from ww w  . j  a v a  2s  .c  o m*/
    TextView tab_text_textview = new TextView(getContext());
    tab_text_textview.setId(position);
    tab_text_textview.setText(title);
    tab_text_textview.setGravity(Gravity.CENTER_VERTICAL);
    tab_text_textview.setSingleLine();
    // tab_text_textview.setTextColor(tabTextColor);
    // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color));
    XmlPullParser xrp = getResources().getXml(tabTextColor);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);

        if (tab_text_textview != null) {
            tab_text_textview.setTextColor(csl);
        }
    } catch (Exception e) {

    }
    tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle);
    LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    if (iconResId != 0) {
        // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds(
        // iconResId, 0, 0, 0);
        // Drawable mDrawable = ((Activity) getContext()).getResources()
        // .getDrawable(iconResId);
        // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(),
        // mDrawable.getMinimumHeight());
        int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding);
        ImageView icon = new ImageView(getContext());
        icon.setImageResource(iconResId);
        icon.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                iIconHeight);

        switch (iIconLocation) {
        case 1:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);

            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 2:
            // tab_text_textview.setCompoundDrawables(null, mDrawable, null,
            // null);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(icon, lpImage);
            lpText.topMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 3:
            // tab_text_textview.setCompoundDrawables(null, null, mDrawable,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.leftMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        case 4:
            // tab_text_textview.setCompoundDrawables(null, null, null,
            // mDrawable);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.topMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        default:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        }

        // tab_text_textview
        // .setCompoundDrawablePadding((int) ((Activity) getContext())
        // .getResources()
        // .getDimension(R.dimen.common_padding));

    } else {
        tabView.addView(tab_text_textview, lpText);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.wangbb.naruto.app.view.PagerSlidingTabStrip.java

private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId,
        int iIconLocation) {
    // final View tabView = ((Activity) getContext()).getLayoutInflater()
    // .inflate(iLayoutResId, null);
    // TextView tab_text_textview = (TextView)
    // tabView.findViewById(iTextId);
    // tab_text_textview.setText(title);
    LinearLayout tabView = new LinearLayout(getContext());
    tabView.setGravity(Gravity.CENTER);//from w  w  w.j  a v  a 2 s.co  m
    TextView tab_text_textview = new TextView(getContext());
    tab_text_textview.setId(position);
    tab_text_textview.setText(title);
    tab_text_textview.setGravity(Gravity.CENTER_VERTICAL);
    tab_text_textview.setSingleLine();
    // tab_text_textview.setTextColor(tabTextColor);
    // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color));
    //      XmlPullParser xrp = getResources().getXml(tabTextColor);
    //      try {
    //         ColorStateList csl = ColorStateList.createFromXml(getResources(),
    //               xrp);

    //         if (tab_text_textview != null) {
    tab_text_textview.setTextColor(tabTextColor);
    //         }
    //      } catch (Exception e) {
    //
    //      }
    tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle);
    LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    if (iconResId != 0) {
        // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds(
        // iconResId, 0, 0, 0);
        // Drawable mDrawable = ((Activity) getContext()).getResources()
        // .getDrawable(iconResId);
        // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(),
        // mDrawable.getMinimumHeight());
        int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding);
        ImageView icon = new ImageView(getContext());
        icon.setImageResource(iconResId);
        icon.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                iIconHeight);

        switch (iIconLocation) {
        case 1:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);

            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 2:
            // tab_text_textview.setCompoundDrawables(null, mDrawable, null,
            // null);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(icon, lpImage);
            lpText.topMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 3:
            // tab_text_textview.setCompoundDrawables(null, null, mDrawable,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.leftMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        case 4:
            // tab_text_textview.setCompoundDrawables(null, null, null,
            // mDrawable);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.topMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        default:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        }

        // tab_text_textview
        // .setCompoundDrawablePadding((int) ((Activity) getContext())
        // .getResources()
        // .getDimension(R.dimen.common_padding));

    } else {
        tabView.addView(tab_text_textview, lpText);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:net.ibaixin.chat.view.PagerSlidingTabStrip.java

/**
 * tab/*from w  ww.j  av  a  2 s  .  c  o m*/
 * @update 2015128 ?9:58:54
 * @param position
 * @param title
 */
private void addTextTab(final int position, CharSequence title) {
    //layout
    RelativeLayout tabLayout = new RelativeLayout(getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tabLayout.setLayoutParams(layoutParams);

    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    textParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    //tab
    TextView tab = new TextView(getContext());
    tab.setId(100 + position);
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tabLayout.addView(tab, textParams);

    //???
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId());
    viewParams.addRule(RelativeLayout.CENTER_VERTICAL);
    View view = new View(getContext());
    ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(vParams);
    tabLayout.addView(view, viewParams);

    addTab(position, tabLayout);

}

From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java

@NonNull
private LinearLayout createBikeLine(@NonNull final BikeStation bikeStation, final boolean firstLine) {
    final LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);//from w w w. j a v  a  2  s.com
    final LinearLayout line = new LinearLayout(context);
    line.setOrientation(LinearLayout.HORIZONTAL);
    line.setLayoutParams(lineParams);

    // Left
    final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    final RelativeLayout left = new RelativeLayout(context);
    left.setLayoutParams(leftParam);

    final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId = Util.generateViewId();
    lineIndication.setId(lineId);

    final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
    availableParam.setMargins(pixelsHalf, 0, 0, 0);

    final TextView boundCustomTextView = new TextView(context);
    boundCustomTextView.setText(activity.getString(R.string.bike_available_docks));
    boundCustomTextView.setSingleLine(true);
    boundCustomTextView.setLayoutParams(availableParam);
    boundCustomTextView.setTextColor(grey5);
    int availableId = Util.generateViewId();
    boundCustomTextView.setId(availableId);

    final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId);
    availableValueParam.setMargins(pixelsHalf, 0, 0, 0);

    final TextView amountBike = new TextView(context);
    final String text = firstLine ? activity.getString(R.string.bike_available_bikes)
            : activity.getString(R.string.bike_available_docks);
    boundCustomTextView.setText(text);
    final Integer data = firstLine ? bikeStation.getAvailableBikes() : bikeStation.getAvailableDocks();
    if (data == null) {
        amountBike.setText("?");
        amountBike.setTextColor(ContextCompat.getColor(context, R.color.orange));
    } else {
        amountBike.setText(String.valueOf(data));
        final int color = data == 0 ? R.color.red : R.color.green;
        amountBike.setTextColor(ContextCompat.getColor(context, color));
    }
    amountBike.setLayoutParams(availableValueParam);

    left.addView(lineIndication);
    left.addView(boundCustomTextView);
    left.addView(amountBike);
    line.addView(left);
    return line;
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleTrains(final int position, View convertView, @NonNull final ViewGroup parent) {
    // Train/*from  ww  w .ja  v  a2  s  . c o  m*/
    final Station station = stations.get(position);
    final Set<TrainLine> trainLines = station.getLines();

    TrainViewHolder viewHolder;
    if (convertView == null || convertView.getTag() == null) {
        final LayoutInflater vi = (LayoutInflater) parent.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.list_nearby, parent, false);

        viewHolder = new TrainViewHolder();
        viewHolder.resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results);
        viewHolder.stationNameView = (TextView) convertView.findViewById(R.id.station_name);
        viewHolder.imageView = (ImageView) convertView.findViewById(R.id.icon);
        viewHolder.details = new HashMap<>();
        viewHolder.arrivalTime = new HashMap<>();

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (TrainViewHolder) convertView.getTag();
    }

    viewHolder.stationNameView.setText(station.getName());
    viewHolder.imageView
            .setImageDrawable(ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_train_white_24dp));

    for (final TrainLine trainLine : trainLines) {
        if (trainArrivals.indexOfKey(station.getId()) != -1) {
            final List<Eta> etas = trainArrivals.get(station.getId()).getEtas(trainLine);
            if (etas.size() != 0) {
                final LinearLayout llv;
                boolean cleanBeforeAdd = false;
                if (viewHolder.details.containsKey(trainLine)) {
                    llv = viewHolder.details.get(trainLine);
                    cleanBeforeAdd = true;
                } else {
                    final LinearLayout llh = new LinearLayout(context);
                    llh.setOrientation(LinearLayout.HORIZONTAL);
                    llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0);

                    llv = new LinearLayout(context);
                    llv.setOrientation(LinearLayout.VERTICAL);
                    llv.setPadding(line1PaddingColor, 0, 0, 0);

                    llh.addView(llv);
                    viewHolder.resultLayout.addView(llh);
                    viewHolder.details.put(trainLine, llv);
                }

                final List<String> keysCleaned = new ArrayList<>();

                for (final Eta eta : etas) {
                    final Stop stop = eta.getStop();
                    final String key = station.getName() + "_" + trainLine.toString() + "_"
                            + stop.getDirection().toString() + "_" + eta.getDestName();
                    if (viewHolder.arrivalTime.containsKey(key)) {
                        final RelativeLayout insideLayout = viewHolder.arrivalTime.get(key);
                        final TextView timing = (TextView) insideLayout.getChildAt(2);
                        if (cleanBeforeAdd && !keysCleaned.contains(key)) {
                            timing.setText("");
                            keysCleaned.add(key);
                        }
                        final String timingText = timing.getText() + eta.getTimeLeftDueDelay() + " ";
                        timing.setText(timingText);
                    } else {
                        final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
                                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        final RelativeLayout insideLayout = new RelativeLayout(context);
                        insideLayout.setLayoutParams(leftParam);

                        final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context,
                                trainLine);
                        int lineId = Util.generateViewId();
                        lineIndication.setId(lineId);

                        final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
                                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
                        availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

                        final TextView stopName = new TextView(context);
                        final String destName = eta.getDestName() + ": ";
                        stopName.setText(destName);
                        stopName.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey_5));
                        stopName.setLayoutParams(availableParam);
                        int availableId = Util.generateViewId();
                        stopName.setId(availableId);

                        final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams(
                                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId);
                        availableValueParam.setMargins(0, 0, 0, 0);

                        final TextView timing = new TextView(context);
                        final String timeLeftDueDelay = eta.getTimeLeftDueDelay() + " ";
                        timing.setText(timeLeftDueDelay);
                        timing.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey));
                        timing.setLines(1);
                        timing.setEllipsize(TruncateAt.END);
                        timing.setLayoutParams(availableValueParam);

                        insideLayout.addView(lineIndication);
                        insideLayout.addView(stopName);
                        insideLayout.addView(timing);

                        llv.addView(insideLayout);
                        viewHolder.arrivalTime.put(key, insideLayout);
                    }
                }
            }
        }
    }
    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, station.getId(),
            station.getStopsPosition().get(0).getLatitude(), station.getStopsPosition().get(0).getLongitude()));
    return convertView;
}

From source file:im.ene.lab.attiq.ui.activities.ProfileActivity.java

private void updateDescription() {
    if (mProfile == null || mDescription == null) {
        return;/*from  ww w .  j a  v  a2s  .co m*/
    }

    // mDescription.removeAllViews();
    final Context context = mDescription.getContext();

    if (mProfile.getContributionCount() != null) {
        TextView contribution = (TextView) mDescription.findViewById(R.id.profile_info_contribution);
        if (contribution == null) {
            contribution = (TextView) LayoutInflater.from(context).inflate(R.layout.widget_info_textview,
                    mDescription, false);
            contribution.setId(R.id.profile_info_contribution);
            mDescription.addView(contribution, 0);
        }

        contribution.setText(getResources().getQuantityString(R.plurals.user_contribution_quantity,
                mProfile.getContributionCount(), mProfile.getContributionCount()));
    }

    if (!UIUtil.isEmpty(mProfile.getDescription())) {
        TextView description = (TextView) mDescription.findViewById(R.id.profile_info_description);
        if (description == null) {
            description = (TextView) LayoutInflater.from(context).inflate(R.layout.widget_info_textview,
                    mDescription, false);
            description.setId(R.id.profile_info_description);
            mDescription.addView(description);
        }
        description.setText(UIUtil.beautify(mProfile.getDescription()));
    }

    if (!UIUtil.isEmpty(mProfile.getOrganization())) {
        UserInfoRowTextView organization = (UserInfoRowTextView) mDescription
                .findViewById(R.id.profile_info_organization);
        if (organization == null) {
            organization = new UserInfoRowTextView(mDescription.getContext());
            organization.setId(R.id.profile_info_organization);
            mDescription.addView(organization);
        }

        organization.setText(UIUtil.beautify(mProfile.getOrganization()));
        organization.setIcon(R.drawable.ic_organization);
    }
}

From source file:org.solovyev.android.messenger.BaseListFragment.java

@Nonnull
private View createListView() {
    final Context context = getThemeContext();

    final FrameLayout root = new FrameLayout(context);

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

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

    final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    progressContainer.addView(progress, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

    root.addView(progressContainer, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

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

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

    final TextView emptyListCaption = new TextView(context);
    emptyListCaption.setId(INTERNAL_EMPTY_ID);
    emptyListCaption.setGravity(CENTER);
    listViewContainer.addView(emptyListCaption, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    final ListViewAwareOnRefreshListener topRefreshListener = getTopPullRefreshListener();
    final ListViewAwareOnRefreshListener bottomRefreshListener = getBottomPullRefreshListener();

    final View listView;

    if (topRefreshListener == null && bottomRefreshListener == null) {
        pullToRefreshMode = null;//  www . j a  va  2s .c o m
        listView = createListView(context);
    } else {
        listView = createPullToRefreshListView(context, topRefreshListener, bottomRefreshListener);
    }

    listViewContainer.addView(listView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    root.addView(listViewContainer, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

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

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

    return root;
}

From source file:ru.adios.budgeter.widgets.DataTableLayout.java

private void populateColumn(TextView view, Context context, float weight) {
    view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT, weight));
    view.setId(ElementsIdProvider.getNextId());
    view.setBackground(ContextCompat.getDrawable(context, R.drawable.cell_shape));
    final int fiveDp = getDpAsPixels(5, context);
    view.setPadding(fiveDp, fiveDp, fiveDp, fiveDp);
    view.setTextAppearance(context, android.R.style.TextAppearance_Small);
}

From source file:com.heath_bar.tvdb.SeriesOverview.java

protected void ShowHideEpisodes(View seasonRow) {

    // Get the linear layout that we will be adding/removing the episodes to/from
    LinearLayout epLinearLayout = (LinearLayout) seasonRow;

    if (epLinearLayout.getChildCount() == 1) { // if collapsed, expand (add) the seasons

        TextView seasonText = (TextView) seasonRow.findViewById(R.id.season_text);
        seasonText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.arrow_down),
                null, null, null);/*from   ww  w .  j  av  a 2  s.  c  om*/

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        for (int i = 0; i < episodeList.size(); i++) {
            if (seasonRow.getId() == episodeList.get(i).getSeason()) {
                View episodeView = inflater.inflate(R.layout.episode_text_row, epLinearLayout, false);

                episodeView.setBackgroundColor(
                        AppSettings.listBackgroundColors[i % AppSettings.listBackgroundColors.length]);

                TextView text = (TextView) episodeView.findViewById(R.id.text);
                String nameText = String.format("%02d", episodeList.get(i).getNumber()) + " "
                        + episodeList.get(i).getName();
                text.setText(nameText);
                text.setTextSize(textSize);
                text.setId(episodeList.get(i).getId());

                episodeView.setOnClickListener(episodeListener);
                epLinearLayout.addView(episodeView);
            }
        }
    } else { // else season is expanded, collapse it
        TextView seasonText = (TextView) seasonRow.findViewById(R.id.season_text);
        seasonText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.arrow_right),
                null, null, null);

        for (int i = epLinearLayout.getChildCount() - 1; i > 0; i--) {
            epLinearLayout.removeView(epLinearLayout.getChildAt(i));
        }

    }

}