List of usage examples for android.widget TextView findViewById
@Nullable public final <T extends View> T findViewById(@IdRes int id)
From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setBackgroundResource(tabBackgroundResId); if (v instanceof TextView) { TextView tab = (TextView) v; tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setTextColor(tabTextColor); // setAllCaps() is only available from API 14, so the upper case // is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab.setAllCaps(true); } else { tab.setText(tab.getText().toString().toUpperCase(locale)); }/*from w w w . ja v a 2s . co m*/ } if (i == selectedPosition) { tab.setTextColor(selectedTabTextColor); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectTabTextSize); } } else if (v instanceof LinearLayout) { LinearLayout tab = (LinearLayout) v; TextView text = (TextView) tab.findViewById(R.id.text); text.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); text.setTypeface(tabTypeface, tabTypefaceStyle); text.setTextColor(tabTextColor); ImageView image = (ImageView) tab.findViewById(R.id.image); image.setImageResource(((IconTabProvider) pager.getAdapter()).getPageIconResId(i)); // setAllCaps() is only available from API 14, so the upper case // is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { text.setAllCaps(true); } else { text.setText(text.getText().toString().toUpperCase(locale)); } } if (i == selectedPosition) { text.setTextColor(selectedTabTextColor); text.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectTabTextSize); image.setImageResource(((IconTabProvider) pager.getAdapter()).getSelectPageIconResId(i)); } } } }
From source file:com.gelakinetic.mtgfam.helpers.ResultListAdapter.java
/** * Binds all of the field names passed into the "to" parameter of the constructor with their corresponding cursor * columns as specified in the "from" parameter. Binding occurs in two phases. First, if a * SimpleCursorAdapter.ViewBinder is available, setViewValue(android.view.View, android.database.Cursor, int) is * invoked. If the returned value is true, binding has occurred. If the returned value is false and the view to bind * is a TextView, setViewText(TextView, String) is invoked. If the returned value is false and the view to bind is * an ImageView, setViewImage(ImageView, String) is invoked. If no appropriate binding can be found, an * IllegalStateException is thrown./* w w w . j ava2 s .co m*/ * * @param view Existing view, returned earlier by newView * @param context Interface to application's global information * @param cursor The cursor from which to get the data. The cursor is already moved to the correct position. */ @Override public void bindView(@NotNull View view, Context context, @NotNull Cursor cursor) { boolean hideCost = true; boolean hideSet = true; boolean hideType = true; boolean hideAbility = true; boolean hidePT = true; boolean hideLoyalty = true; boolean hideRarity = true; /* make sure these elements are showing (views get recycled) */ view.findViewById(R.id.cardp).setVisibility(View.VISIBLE); view.findViewById(R.id.cardslash).setVisibility(View.VISIBLE); view.findViewById(R.id.cardt).setVisibility(View.VISIBLE); /* Iterate through the mFrom, find the appropriate view in mTo */ for (int i = 0; i < mFrom.length; i++) { TextView textField = (TextView) view.findViewById(mTo[i]); switch (mFrom[i]) { case CardDbAdapter.KEY_NAME: { String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); textField.setText(name); break; } case CardDbAdapter.KEY_MANACOST: { String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); hideCost = false; CharSequence csq = ImageGetterHelper.formatStringWithGlyphs(name, mImgGetter); textField.setText(csq); break; } case CardDbAdapter.KEY_SET: { char rarity = (char) cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_RARITY)); String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); hideSet = false; textField.setText(name); switch (rarity) { case 'c': case 'C': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_common))); break; case 'u': case 'U': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_uncommon))); break; case 'r': case 'R': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_rare))); break; case 'm': case 'M': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_mythic))); break; case 't': case 'T': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_timeshifted))); break; } break; } case CardDbAdapter.KEY_RARITY: { char rarity = (char) cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_RARITY)); textField.setText("(" + rarity + ")"); hideRarity = false; break; } case CardDbAdapter.KEY_SUPERTYPE: { String name = CardDbAdapter.getTypeLine(cursor); hideType = false; textField.setText(name); break; } case CardDbAdapter.KEY_ABILITY: { String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); hideAbility = false; CharSequence csq = ImageGetterHelper.formatStringWithGlyphs(name, mImgGetter); textField.setText(csq); break; } case CardDbAdapter.KEY_POWER: float p = cursor.getFloat(cursor.getColumnIndex(mFrom[i])); if (p != CardDbAdapter.NO_ONE_CARES) { String pow; hidePT = false; if (p == CardDbAdapter.STAR) pow = "*"; else if (p == CardDbAdapter.ONE_PLUS_STAR) pow = "1+*"; else if (p == CardDbAdapter.TWO_PLUS_STAR) pow = "2+*"; else if (p == CardDbAdapter.SEVEN_MINUS_STAR) pow = "7-*"; else if (p == CardDbAdapter.STAR_SQUARED) pow = "*^2"; else if (p == CardDbAdapter.X) pow = "X"; else { if (p == (int) p) { pow = Integer.valueOf((int) p).toString(); } else { pow = Float.valueOf(p).toString(); } } textField.setText(pow); } break; case CardDbAdapter.KEY_TOUGHNESS: float t = cursor.getFloat(cursor.getColumnIndex(mFrom[i])); if (t != CardDbAdapter.NO_ONE_CARES) { hidePT = false; String tou; if (t == CardDbAdapter.STAR) tou = "*"; else if (t == CardDbAdapter.ONE_PLUS_STAR) tou = "1+*"; else if (t == CardDbAdapter.TWO_PLUS_STAR) tou = "2+*"; else if (t == CardDbAdapter.SEVEN_MINUS_STAR) tou = "7-*"; else if (t == CardDbAdapter.STAR_SQUARED) tou = "*^2"; else if (t == CardDbAdapter.X) tou = "X"; else { if (t == (int) t) { tou = Integer.valueOf((int) t).toString(); } else { tou = Float.valueOf(t).toString(); } } textField.setText(tou); } break; case CardDbAdapter.KEY_LOYALTY: float l = cursor.getFloat(cursor.getColumnIndex(mFrom[i])); if (l != CardDbAdapter.NO_ONE_CARES) { hideLoyalty = false; if (l == CardDbAdapter.X) { ((TextView) textField.findViewById(R.id.cardt)).setText("X"); } else if (l == (int) l) { ((TextView) textField.findViewById(R.id.cardt)).setText(Integer.toString((int) l)); } else { ((TextView) textField.findViewById(R.id.cardt)).setText(Float.toString(l)); } } break; } } /* Hide the fields if they should be hidden (didn't exist in mTo)*/ if (hideCost) { view.findViewById(R.id.cardcost).setVisibility(View.GONE); } if (hideSet) { view.findViewById(R.id.cardset).setVisibility(View.GONE); } if (hideType) { view.findViewById(R.id.cardtype).setVisibility(View.GONE); } if (hideAbility) { view.findViewById(R.id.cardability).setVisibility(View.GONE); } if (!hideLoyalty) { view.findViewById(R.id.cardp).setVisibility(View.GONE); view.findViewById(R.id.cardslash).setVisibility(View.GONE); } else if (hidePT) { view.findViewById(R.id.cardp).setVisibility(View.GONE); view.findViewById(R.id.cardslash).setVisibility(View.GONE); view.findViewById(R.id.cardt).setVisibility(View.GONE); } if (hideRarity) { view.findViewById(R.id.rarity).setVisibility(View.GONE); } }