List of usage examples for android.view LayoutInflater from
public static LayoutInflater from(Context context)
From source file:br.com.cast.treinamento.tabs.SlidingTabLayout.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/* ww w .ja v a2s . c om*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate // it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } CharSequence pageTitle = adapter.getPageTitle(i); int drawableId; Drawable drawable = null; int density = (int) getResources().getDisplayMetrics().density; try { drawableId = Integer.parseInt(pageTitle.toString().trim()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = getResources().getDrawable(drawableId); } else { drawable = getResources().getDrawable(drawableId, null); } } catch (NumberFormatException e) { // e.printStackTrace(); } if (drawable == null) { tabTitleView.setText(pageTitle); } else { drawable.setBounds(0, 0, 24 * density, 24 * density); tabTitleView.setCompoundDrawables(drawable, null, null, null); tabTitleView.setText(""); } tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:net.naonedbus.card.impl.CommentairesCard.java
@Override public void onLoadFinished(final Loader<List<Commentaire>> loader, final List<Commentaire> commentaires) { if (commentaires == null || commentaires.isEmpty()) { showMessage(R.string.msg_nothing_commentaires, R.drawable.ic_checkmark_holo_light); } else {// w w w .j av a2s . com final LayoutInflater inflater = LayoutInflater.from(getContext()); mRoot.removeAllViews(); for (final Commentaire commentaire : commentaires) { mRoot.addView(createView(inflater, mRoot, commentaire)); } showContent(); } }
From source file:br.com.diegomelo.exemploslidingtabs.activity.widget.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;// ww w . j ava2 s. com TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector)); tabTitleView.setTextSize(14); } }
From source file:alvi17.mathformula.model.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from w ww . j ava 2 s . co m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:adi.sf1.targaryen.newyorktimes.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/* w w w.j a v a 2 s .c om*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:br.comoferta.ui.view.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from w ww .j a v a2s .c o m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i).toString().toUpperCase()); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java
private void initTitle() { if (mTitleLayout == null) { LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(R.layout.abs__action_bar_title_item, this); mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1); mTitleView = (TextView) mTitleLayout.findViewById(R.id.abs__action_bar_title); mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.abs__action_bar_subtitle); if (mTitleStyleRes != 0) { mTitleView.setTextAppearance(mContext, mTitleStyleRes); }// ww w . ja v a 2 s. c o m if (mSubtitleStyleRes != 0) { mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes); } } mTitleView.setText(mTitle); mSubtitleView.setText(mSubtitle); final boolean hasTitle = !TextUtils.isEmpty(mTitle); final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle); mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE); mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE); if (mTitleLayout.getParent() == null) { addView(mTitleLayout); } }
From source file:android.support.v7.internal.widget.ActionBarContextView.java
public void initForMode(final ActionMode mode) { if (mClose == null) { LayoutInflater inflater = LayoutInflater.from(getContext()); mClose = inflater.inflate(mCloseItemLayout, this, false); addView(mClose);//from w w w. j a va 2 s.c om } else if (mClose.getParent() == null) { addView(mClose); } View closeButton = mClose.findViewById(R.id.action_mode_close_button); closeButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mode.finish(); } }); final MenuBuilder menu = (MenuBuilder) mode.getMenu(); if (mActionMenuPresenter != null) { mActionMenuPresenter.dismissPopupMenus(); } mActionMenuPresenter = new ActionMenuPresenter(getContext()); mActionMenuPresenter.setReserveOverflow(true); final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); if (!mSplitActionBar) { menu.addMenuPresenter(mActionMenuPresenter, mPopupContext); mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(null); addView(mMenuView, layoutParams); } else { // Allow full screen width in split mode. mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true); // No limit to the item count; use whatever will fit. mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); // Span the whole width layoutParams.width = LayoutParams.MATCH_PARENT; layoutParams.height = mContentHeight; menu.addMenuPresenter(mActionMenuPresenter, mPopupContext); mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(mSplitBackground); mSplitView.addView(mMenuView, layoutParams); } mAnimateInOnLayout = true; }
From source file:com.handlerexploit.news.fragments.WeatherFragment.java
private void render(WeatherInfo weatherInfo) { Activity activity = getActivity();//from ww w. ja va 2 s . c o m if (activity != null && weatherInfo != null) { View root = getView(); TextView city = (TextView) root.findViewById(R.id.city); city.setText(weatherInfo.getCity()); CurrentWeather currentWeather = weatherInfo.getCurrentWeather(); RemoteImageView icon = (RemoteImageView) root.findViewById(R.id.icon); int resId = activity.getResources().getIdentifier(currentWeather.getIcon(), "drawable", activity.getPackageName()); if (resId != 0) { ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(resId); icon.setImageResource(resId); } else { ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(R.drawable.unknown); icon.setImageResource(R.drawable.unknown); } TextView temp = (TextView) root.findViewById(R.id.temp); temp.setText(currentWeather.getTempF() + " \u00B0F | " + currentWeather.getTempC() + " \u00B0C"); ((TextView) activity.findViewById(R.id.weather_small_text)) .setText(currentWeather.getTempF() + "\u00B0"); TextView condition = (TextView) root.findViewById(R.id.condition); String conditionText = currentWeather.getCondition(); if (conditionText != null && !conditionText.equals("")) { condition.setText(conditionText); } else { condition.setText("N/A"); } TextView windCondition = (TextView) root.findViewById(R.id.windCondition); windCondition.setText(currentWeather.getWindCondition()); TextView humidity = (TextView) root.findViewById(R.id.humidity); humidity.setText(currentWeather.getHumidity()); LinearLayout forcastConditions = (LinearLayout) root.findViewById(R.id.forcastConditions); forcastConditions.removeAllViews(); LayoutInflater inflater = LayoutInflater.from(activity); LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); params.weight = 1f; ArrayList<Condition> forcastArray = weatherInfo.getForcastConditions(); for (int i = 0; i < forcastArray.size(); i++) { Condition forcastCondition = forcastArray.get(i); View forcastRoot = inflater.inflate(R.layout.fragment_weather_condition_item, null); TextView forcastDay = (TextView) forcastRoot.findViewById(R.id.day); forcastDay.setText(forcastCondition.getDay()); RemoteImageView forcastIcon = (RemoteImageView) forcastRoot.findViewById(R.id.icon); int forcastResId = activity.getResources().getIdentifier(forcastCondition.getIcon(), "drawable", activity.getPackageName()); if (forcastResId != 0) { forcastIcon.setImageResource(forcastResId); } else { forcastIcon.setImageResource(R.drawable.unknown); } TextView forcastHigh = (TextView) forcastRoot.findViewById(R.id.high); forcastHigh.setText(forcastCondition.getHigh() + "\u00B0"); TextView forcastLow = (TextView) forcastRoot.findViewById(R.id.low); forcastLow.setText(forcastCondition.getLow() + "\u00B0"); forcastConditions.addView(forcastRoot, params); } } }
From source file:br.com.luizgadao.selfdestruction.views.android.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); //custom width int customW = getResources().getDisplayMetrics().widthPixels / mViewPager.getAdapter().getCount(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from w ww. j av a2 s .c o m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); //set custom width for tabview tabView.setMinimumWidth(customW); mTabStrip.addView(tabView); } }