Java Code Examples for android.view.LayoutInflater.from()

The following are Jave code examples for showing how to use from() of the android.view.LayoutInflater class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Hitalk   File: SpringView.java   Source Code and License Vote up 6 votes
public SpringView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    inflater = LayoutInflater.from(context);

    mScroller = new OverScroller(context);

    //获取自定义属性
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SpringView);
    if (ta.hasValue(R.styleable.SpringView_type)){
        int type_int = ta.getInt(R.styleable.SpringView_type, 0);
        type = Type.values()[type_int];
    }
    if (ta.hasValue(R.styleable.SpringView_give)){
        int give_int = ta.getInt(R.styleable.SpringView_give, 0);
        give = Give.values()[give_int];
    }
    if (ta.hasValue(R.styleable.SpringView_header)){
        headerResoureId = ta.getResourceId(R.styleable.SpringView_header, 0);
    }
    if (ta.hasValue(R.styleable.SpringView_footer)){
        footerResoureId = ta.getResourceId(R.styleable.SpringView_footer, 0);
    }
    ta.recycle();
}
 
Example 2
Project: MainCalendar   File: ToolBarHelper.java   Source Code and License Vote up 5 votes
ToolBarHelper(Context context, int layoutId) {
    this.mContext = context;
    mInflater = LayoutInflater.from(mContext);
    /*初始化整个内容*/
    initContentView();
    /*初始化用户定义的布局*/
    initUserView(layoutId);
    /*初始化toolbar*/
    initToolBar();
}
 
Example 3
Project: android-dev-challenge   File: GreenAdapter.java   Source Code and License Vote up 5 votes
/**
 *
 * This gets called when each new ViewHolder is created. This happens when the RecyclerView
 * is laid out. Enough ViewHolders will be created to fill the screen and allow for scrolling.
 *
 * @param viewGroup The ViewGroup that these ViewHolders are contained within.
 * @param viewType  If your RecyclerView has more than one type of item (which ours doesn't) you
 *                  can use this viewType integer to provide a different layout. See
 *                  {@link android.support.v7.widget.RecyclerView.Adapter#getItemViewType(int)}
 *                  for more details.
 * @return A new NumberViewHolder that holds the View for each list item
 */
@Override
public NumberViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    Context context = viewGroup.getContext();
    int layoutIdForListItem = R.layout.number_list_item;
    LayoutInflater inflater = LayoutInflater.from(context);
    boolean shouldAttachToParentImmediately = false;

    View view = inflater.inflate(layoutIdForListItem, viewGroup, shouldAttachToParentImmediately);
    NumberViewHolder viewHolder = new NumberViewHolder(view);

    return viewHolder;
}
 
Example 4
Project: AgentWeb   File: DefaultDesignUIController.java   Source Code and License Vote up 5 votes
@Override
protected void bindSupportWebParent(WebParentLayout webParentLayout, Activity activity) {
    super.bindSupportWebParent(webParentLayout, activity);
    this.mActivity = activity;
    this.mWebParentLayout = webParentLayout;
    mLayoutInflater = LayoutInflater.from(mActivity);
}
 
Example 5
Project: GitHub   File: EmoticonsAdapter.java   Source Code and License Vote up 5 votes
public EmoticonsAdapter(Context context, EmoticonPageEntity emoticonPageEntity, EmoticonClickListener onEmoticonClickListener) {
    this.mContext = context;
    this.mInflater = LayoutInflater.from(context);
    this.mEmoticonPageEntity = emoticonPageEntity;
    this.mOnEmoticonClickListener = onEmoticonClickListener;
    this.mItemHeightMaxRatio = DEF_HEIGHTMAXTATIO;
    this.mDelbtnPosition = -1;
    this.mDefalutItemHeight = this.mItemHeight = (int) context.getResources().getDimension(R.dimen.item_emoticon_size_default);
    this.mData.addAll(emoticonPageEntity.getEmoticonList());
    checkDelBtn(emoticonPageEntity);
}
 
Example 6
Project: Trackr   File: SearchFriendListAdapter.java   Source Code and License Vote up 5 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    User user = getItem(position);
    // Check if an existing view is being reused, otherwise inflate the view
    ViewHolder viewHolder; // view lookup cache stored in tag

    final View result;

    if (convertView == null) {

        viewHolder = new ViewHolder();
        LayoutInflater inflater = LayoutInflater.from(getContext());
        convertView = inflater.inflate(R.layout.list_search_friend, parent, false);
        viewHolder.textViewSearchFriendName = (TextView) convertView.findViewById(R.id.textViewSearchFriendName);
        viewHolder.textViewSearchFriendId= (TextView) convertView.findViewById(R.id.textViewSearchFriendId);


        result=convertView;

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

    Animation animation = AnimationUtils.loadAnimation(mContext, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
    result.startAnimation(animation);
    lastPosition = position;

    viewHolder.textViewSearchFriendId.setText(String.valueOf(user.getId()));
    viewHolder.textViewSearchFriendName.setText(user.getFname() + " " + user.getLname());
    // Return the completed view to render on screen
    return convertView;
}
 
Example 7
Project: Crypto-Assistant   File: NewsAdapter.java   Source Code and License Vote up 5 votes
public NewsAdapter(Context context, RealmResults<Article> articles) {
    try {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.articles = articles;
    } catch (Exception e) {
        e.printStackTrace();
    }


}
 
Example 8
Project: reactive-architectures-playground   File: FactsAdapterTests.java   Source Code and License Vote up 5 votes
@Test public void shouldCrash_WhenDataAvailable_ForViewTypes() {
    Activity host = buildActivity(FactsAboutNumbersActivity.class).create().get();
    adapter = new FactsAdapter(LayoutInflater.from(host));

    assertThat(adapter.getItemCount()).isEqualTo(0);

    ThrowingCallable call = () -> adapter.getItemViewType(0);
    assertThatThrownBy(call).isInstanceOf(IllegalStateException.class);
}
 
Example 9
Project: Chore-Manager-App   File: CustomMaterialListAdapter.java   Source Code and License Vote up 4 votes
public View getCustomView(final int position, View convertView,
                          ViewGroup parent) {

    final ViewHolder holder;
    if (convertView == null) {
        LayoutInflater layoutInflator = LayoutInflater.from(mContext);
        convertView = layoutInflator.inflate(R.layout.special_materials_spinner, null);
        holder = new ViewHolder();
        holder.mTextView = (TextView) convertView
                .findViewById(R.id.text);
        holder.mCheckBox = (CheckBox) convertView
                .findViewById(R.id.checkbox);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.mTextView.setText(listState.get(position).getTitle());

    if (position == 0) {
        holder.mCheckBox.setVisibility(View.VISIBLE);
    } else {
        holder.mCheckBox.setVisibility(View.VISIBLE);
    }

    holder.mCheckBox.setTag(position);
    holder.mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            //If box is clicked, set it to true;
            int getPosition = (Integer) buttonView.getTag();
            if (isChecked){
                listState.get(getPosition).setSelected(true);
            }
            else{
                listState.get(getPosition).setSelected(false);
            }


        }
    });
    return convertView;
}
 
Example 10
Project: GitHub   File: HomeRecycleAdapter.java   Source Code and License Vote up 4 votes
public HomeRecycleAdapter(Context mContext, ResultBean resultBean) {
    this.mContext = mContext;
    this.resultBean = resultBean;
    mLayoutInflater = LayoutInflater.from(mContext);
}
 
Example 11
Project: wisebite_android   File: OrderItemAdapter.java   Source Code and License Vote up 4 votes
@Override
public OrderItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
    View view = layoutInflater.inflate(R.layout.order_dish_item, parent, false);
    return new OrderItemHolder(view);
}
 
Example 12
Project: yaacc-code   File: PlayerListItemAdapter.java   Source Code and License Vote up 4 votes
private void initialize() {
    inflator = LayoutInflater.from(upnpClient.getContext());
    players = upnpClient.getCurrentPlayers();

}
 
Example 13
Project: VirtualHook   File: LaunchpadAdapter.java   Source Code and License Vote up 4 votes
public LaunchpadAdapter(Context context) {
    mInflater = LayoutInflater.from(context);
}
 
Example 14
Project: BalaFM   File: SearchResultAnchor.java   Source Code and License Vote up 4 votes
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater inflater=LayoutInflater.from(parent.getContext());
    View view=inflater.inflate(R.layout.bar_search_anchor,parent,false);
    return new ViewHolder(view);
}
 
Example 15
Project: recyclerview-android   File: Adapter.java   Source Code and License Vote up 4 votes
@Override
public final VH onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    return onCreateViewHolder(inflater, parent, viewType);
}
 
Example 16
Project: LocationAware   File: ActivityModule.java   Source Code and License Vote up 4 votes
@ActivityScope
@Provides LayoutInflater provideLayoutInflater(@ActivityContext Context context) {
  return LayoutInflater.from(context);
}
 
Example 17
Project: BLG-411E   File: RecipeAdapter.java   Source Code and License Vote up 4 votes
@Override
public View getView(int position, View convertView, ViewGroup parent){

    View row = convertView;
    RecipeAdapter.RecipeHolder holder = null;

    if(row == null){
        //Create a new view
        LayoutInflater inflater = LayoutInflater.from(mContext);
        row = inflater.inflate(mLayoutResourceId,parent,false);

        holder = new RecipeAdapter.RecipeHolder();

        holder.nameView = (TextView) row.findViewById(R.id.nameTextView);
        holder.infoView = (TextView) row.findViewById(R.id.infoTextView);
        holder.imageView = (ImageView) row.findViewById(R.id.imageView);

        row.setTag(holder);
    }else{
        //Otherwise use an existing one
        holder = (RecipeAdapter.RecipeHolder) row.getTag();
    }

    //Getting the data form the data array
    Recipe Re = mData[position];

    //Setup and reuse the same listener for each row
    holder.imageView.setOnClickListener(PopupListener);
    Integer rowPosition = position;
    holder.imageView.setTag(rowPosition);

    //setting the view to reflect the data we need to display
    holder.nameView.setText(Re.get_recipe_name());
    holder.infoView.setText(Re.getRecipe_id());

    //for getting the image
    int resId = mContext.getResources().getIdentifier(Re.NameOfImage,"drawable",mContext.getPackageName());
    holder.imageView.setImageResource(resId);

    //returnning the row view (because this is called getView after all)
    return row;
}
 
Example 18
Project: UltimateRefreshView   File: BaseFooterAdapter.java   Source Code and License Vote up 4 votes
public BaseFooterAdapter(Context context) {
    mInflater = LayoutInflater.from(context);
}
 
Example 19
Project: Kasumi   File: AccountListAdapter.java   Source Code and License Vote up 4 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row;
    AccountHolder holder;
    LayoutInflater inflater = LayoutInflater.from(context);
    row = inflater.inflate(layoutResourceId, parent, false);
    holder = new AccountHolder();
    holder.loadedIcon = (ImageView) row.findViewById(R.id.account_isLoaded);
    holder.accountName = (TextView) row.findViewById(R.id.account_name);
    holder.folderIcon = (ImageView) row.findViewById(R.id.account_isFolder);
    holder.info = (TextView) row.findViewById(R.id.account_info);
    holder.friend_code = (TextView) row.findViewById(R.id.friend_code);
    holder.serverId = (TextView) row.findViewById(R.id.account_server);
    holder.lockedIcon = (ImageView) row.findViewById(R.id.account_locked);
    holder.accountNotSelected= (ImageView) row.findViewById(R.id.account_not_selected);
    holder.accountSelected = (ImageView) row.findViewById(R.id.account_selected);
    holder.itemCount = (TextView) row.findViewById(R.id.account_itemCount);
    Account account = data.get(position);
    holder.accountName.setText(account.name);
    if (account.locked == true) {
        holder.lockedIcon.setVisibility(View.VISIBLE);
    } else {
        holder.lockedIcon.setVisibility(View.GONE);
    }
    if (account.isFolder) {
        holder.folderIcon.setVisibility(View.VISIBLE);
        holder.loadedIcon.setVisibility(View.INVISIBLE);
        holder.info.setVisibility(View.GONE);
        holder.friend_code.setVisibility(View.GONE);
        holder.serverId.setVisibility(View.GONE);
        holder.accountSelected.setVisibility(View.GONE);
        holder.accountNotSelected.setVisibility(View.GONE);
        if (KRFAM.SHOW_ACCOUNT_COUNT_FOLDER){
            holder.itemCount.setVisibility(View.VISIBLE);
            if (account.accountCount == 1) {
                holder.itemCount.setText(KRFAM.s(R.string.item_account,account.accountCount));
            }else {
                holder.itemCount.setText(KRFAM.s(R.string.item_accounts,account.accountCount));
            }
        }else{
            holder.itemCount.setVisibility(View.GONE);
        }
    } else {
        holder.itemCount.setVisibility(View.GONE);
        holder.serverId.setVisibility(View.VISIBLE);
        holder.serverId.setText(account.server);
        holder.folderIcon.setVisibility(View.GONE);
        holder.info.setVisibility(View.VISIBLE);
        if (account.loaded == 0) holder.info.setText(R.string.last_loaded_never);
        else
            holder.info.setText(res.getString(R.string.last_loaded, TimeAgo.toDuration(System.currentTimeMillis() - account.loaded, context)));
            holder.friend_code.setText(res.getString(R.string.id, account.u_Code));
        if (account.isCurrent()) {
            holder.loadedIcon.setVisibility(View.VISIBLE);
        } else {
            holder.loadedIcon.setVisibility(View.INVISIBLE);
        }
        if (MainActivity.selectedAccounts.size() == 0 || account.locked){
            holder.accountSelected.setVisibility(View.GONE);
            holder.accountNotSelected.setVisibility(View.GONE);
        }else {
            if (MainActivity.selectedAccounts.contains(account.id)) {
                holder.accountSelected.setVisibility(View.VISIBLE);
                holder.accountNotSelected.setVisibility(View.GONE);
            } else {
                holder.accountSelected.setVisibility(View.GONE);
                holder.accountNotSelected.setVisibility(View.VISIBLE);
            }
        }
    }
    return row;
}
 
Example 20
Project: android-permission-checker-app   File: AppDetailFragModule.java   Source Code and License Vote up 4 votes
@Provides LayoutInflater provideLayoutInflater(@ActivityContext Context context) {
  return LayoutInflater.from(context);
}