Java Code Examples for android.view.ViewGroup#getContext()

The following examples show how to use android.view.ViewGroup#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File:    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override public SearchResultItemView onCreateViewHolder(ViewGroup parent, int viewType) {
  final Context context = parent.getContext();
  View view = LayoutInflater.from(context)
      .inflate(viewType, parent, false);

  switch (viewType) {
    case SearchResultViewHolder.LAYOUT: {
      return new SearchResultViewHolder(view, onItemViewClick, query);

    case SearchResultAdViewHolder.LAYOUT: {
      return new SearchResultAdViewHolder(view, onAdClickRelay, oneDecimalFormatter);

    default: {
      return new SearchLoadingViewHolder(view);
Example 2
Source File:    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
public Object instantiateItem(ViewGroup container, int position) {
    Picture picture = mData.get(position);
    CenterCropImageView imageView = new CenterCropImageView(container.getContext());

    int w = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    int h = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);

    imageView.measure(w, h);

            .setQiniu(width, height)
            .setDefaultDrawable(new ColorDrawable(0xffe0dedc))
    imageView.setOnClickListener(v -> {
        if (null != mOnImageClickListener) {
    return imageView;
Example 3
Source File:    From NIM_Android_UIKit with MIT License 6 votes vote down vote up
public K onCreateViewHolder(ViewGroup parent, int viewType) {
    K baseViewHolder;
    this.mContext = parent.getContext();
    this.mLayoutInflater = LayoutInflater.from(mContext);
    switch (viewType) {
        case FETCHING_VIEW:
            baseViewHolder = getFetchingView(parent);
        case LOADING_VIEW:
            baseViewHolder = getLoadingView(parent);
        case EMPTY_VIEW:
            baseViewHolder = createBaseViewHolder(mEmptyView);
            baseViewHolder = onCreateDefViewHolder(parent, viewType);
    return baseViewHolder;

Example 4
Source File:    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 6 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View homeView = inflater.inflate(R.layout.fragment_home, container, false);
    // Inflate the layout for this fragment
    // Extract tweets
    ArrayList<TweetModel> tweets = QueryUtils.extractTweets();

    // Setup Home Page Feed Adapter
    FeedAdapter adapter = new FeedAdapter(container.getContext(), tweets);

    //Setup RecyclerView from layout
    RecyclerView recyclerView = homeView.findViewById(;
    //  Setting up linear layout for Recycler View
    LinearLayoutManager layoutManager = new LinearLayoutManager(container.getContext(), LinearLayoutManager.VERTICAL, false);

    return homeView;
Example 5
Source File:    From delion with Apache License 2.0 5 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    mContext = container.getContext();

    // We know which profile to edit based on the GUID stuffed in
    // our extras by AutofillPreferences.
    Bundle extras = getArguments();
    if (extras != null) {
        mGUID = extras.getString(AutofillPreferences.AUTOFILL_GUID);
    if (mGUID == null) {
        mGUID = "";
        mIsNewEntry = true;
    } else {
        mIsNewEntry = false;

    // Hide the top shadow on the ScrollView because the toolbar draws one.
    FadingEdgeScrollView scrollView = (FadingEdgeScrollView) inflater.inflate(
            R.layout.autofill_editor_base, container, false);
    scrollView.setShadowVisibility(false, true);

    // Inflate the editor and buttons into the "content" LinearLayout.
    LinearLayout contentLayout = (LinearLayout) scrollView.findViewById(;
    inflater.inflate(getLayoutId(), contentLayout, true);
    inflater.inflate(R.layout.autofill_editor_base_buttons, contentLayout, true);

    return scrollView;
Example 6
Source File:    From expandable-recyclerview with MIT License 5 votes vote down vote up
public GroupVH onCreateGroupViewHolder(ViewGroup parent, int viewType) {
    Log.d(TAG, ">>> onCreateGroupViewHolder: " + viewType);
    Context context = parent.getContext();
    if (viewType == Shop.TYPE_ALL) {
        return new AllVH(LayoutInflater.from(context).inflate(R.layout.v_item_group_all, parent, false));
    } else if (viewType == Shop.TYPE_OFFLINE) {
        return new OffLineVH(LayoutInflater.from(context).inflate(R.layout.v_item_group_offline, parent, false));
    } else {
        return new OnLineVH(LayoutInflater.from(context).inflate(R.layout.v_item_group_online, parent, false));
Example 7
Source File:    From monero-wallet-android-app with MIT License 5 votes vote down vote up
public RecyclerView.ViewHolder createLoadingViewHolder(ViewGroup parent) {
    FrameLayout frameLayout = new FrameLayout(parent.getContext());
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    ProgressBar progressBar = new ProgressBar(parent.getContext());
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;

    return new StatusViewHolder(frameLayout);
Example 8
Source File:    From HomeApplianceMall with MIT License 5 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_classify, container, false);
    canAC = true;
    myApplication = (MyApplication)getActivity().getApplication();
    listView = (ListView) v.findViewById(;
    refreshLayout = (SwipeRefreshLayout) v.findViewById(;
    layoutTv = (LinearLayout) v.findViewById(;
    layoutFridge = (LinearLayout) v.findViewById(;
    layoutAir = (LinearLayout) v.findViewById(;
    layoutGeyser = (LinearLayout) v.findViewById(;
    layoutWasher = (LinearLayout) v.findViewById(;
    kindMap = new HashMap<>();
    listList = new ArrayList<>();

    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        public void onRefresh() {
            // 刷新操作
            int kind = myApplication.getCurrentKind();
                kind = -1*kind;

    myAdape = new MyAdapterForListGoods(container.getContext(),listList);
    return v;
Example 9
Source File:    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    View contactView = inflater.inflate(R.layout.item_devide_frame, parent, false);
    ItemViewHolder viewHolder = new ItemViewHolder(contactView);
    return viewHolder;
Example 10
Source File:    From Dashchan with Apache License 2.0 5 votes vote down vote up
public View getView(int position, View convertView, ViewGroup parent) {
	ListItem listItem = getItem(position);
	ViewHolder viewHolder;
	if (convertView == null) {
		viewHolder = new ViewHolder();
		View view = LayoutInflater.from(parent.getContext()).inflate(layoutResId, parent, false);
		if (listItem.checkable) {
			LinearLayout linearLayout = new LinearLayout(parent.getContext());
			linearLayout.addView(view, new LinearLayout.LayoutParams(0,
					LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
			CheckBox checkBox = new CheckBox(parent.getContext());
			int paddingRight = view.getPaddingRight() - (int) (4f * ResourceUtils.obtainDensity(view));
			checkBox.setPadding(checkBox.getPaddingLeft(), checkBox.getPaddingTop(),
					Math.max(checkBox.getPaddingRight(), paddingRight), checkBox.getPaddingBottom());
			linearLayout.addView(checkBox, LinearLayout.LayoutParams.WRAP_CONTENT,
			viewHolder.checkBox = checkBox;
			view = linearLayout;
		viewHolder.textView = view.findViewById(;
		convertView = view;
	} else {
		viewHolder = (ViewHolder) convertView.getTag();
	if (listItem.checkable) {
	return convertView;
Example 11
Source File:    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    View view = getLayoutInflater().inflate(R.layout.makeup_product_row, parent, false);
    ProductViewHolder viewHolder = new ProductViewHolder(view);
    return viewHolder;
Example 12
Source File:    From ProjectX with Apache License 2.0 5 votes vote down vote up
ViewHolder(ViewGroup parent) {
    super(new AppCompatTextView(parent.getContext()));
    mVText = (AppCompatTextView) itemView;
Example 13
Source File:    From AndroidTvDemo with Apache License 2.0 5 votes vote down vote up
public FocusBorder build(ViewGroup parent)
    if (null == parent)
        throw new NullPointerException("The FocusBorder parent cannot be null");
    final ColorFocusBorder boriderView =
        new ColorFocusBorder(parent.getContext(), mShimmerColor, mShimmerDuration, mIsShimmerAnim,
            mAnimDuration, mPaddingOfsetRectF, mShadowColor, mShadowWidth, mBorderColor, mBorderWidth);
    final ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(1, 1);
    parent.addView(boriderView, lp);
    return boriderView;
Example 14
Source File:    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
 * 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}
 *                  for more details.
 * @return A new NumberViewHolder that holds the View for each list item
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 15
Source File:    From ShareSDKShareDifMsgDemo-Android with MIT License 4 votes vote down vote up
public View getView(int position, View convertView, ViewGroup parent) {
	FollowListItem item = null;
	if (convertView == null) {
		LinearLayout llItem = new LinearLayout(parent.getContext());
		item = new FollowListItem();
		convertView = llItem;

		item.aivIcon = new AsyncImageView(getContext());
		int dp_52 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 52);
		int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 10);
		int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 5);
		LinearLayout.LayoutParams lpIcon = new LinearLayout.LayoutParams(dp_52, dp_52);
		lpIcon.gravity = Gravity.CENTER_VERTICAL;
		lpIcon.setMargins(dp_10, dp_5, dp_10, dp_5);

		LinearLayout llText = new LinearLayout(parent.getContext());
		llText.setPadding(0, dp_10, dp_10, dp_10);
		LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lpText.gravity = Gravity.CENTER_VERTICAL;
		lpText.weight = 1;

		item.tvName = new TextView(parent.getContext());
		item.tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);

		item.tvSign = new TextView(parent.getContext());
		item.tvSign.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);

		item.ivCheck = new ImageView(parent.getContext());
		item.ivCheck.setPadding(0, 0, dp_10, 0);
		LinearLayout.LayoutParams lpCheck = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lpCheck.gravity = Gravity.CENTER_VERTICAL;
	} else {
		item = (FollowListItem) convertView.getTag();

	Following following = getItem(position);
	item.ivCheck.setImageBitmap(following.checked ? bmChd : bmUnch);
	if (isFling()) {
		Bitmap bm = BitmapProcessor.getBitmapFromCache(following.icon);
		if (bm != null && !bm.isRecycled()) {
		} else {
			item.aivIcon.execute(null, AsyncImageView.DEFAULT_TRANSPARENT);
	} else {

	if (position == getCount() - 1) {
	return convertView;
Example 16
Source File:    From rv-adapter-states with MIT License 4 votes vote down vote up
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return new ItemViewHolder(new TextView(parent.getContext()));
Example 17
Source File:    From KA27 with Apache License 2.0 4 votes vote down vote up
public View getView(ViewGroup viewGroup) {
    return new SeekBarCardView(viewGroup.getContext(), list);
Example 18
Source File:    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
public NarrowImageViewHolder(ViewGroup parent) {
    super(new ImageView(parent.getContext()));
    imgPicture = (ImageView) itemView;
    imgPicture.setLayoutParams(new ViewGroup.LayoutParams((int) AppUtils.convertDpToPixel(72f,getContext()), ViewGroup.LayoutParams.MATCH_PARENT));
Example 19
Source File:    From CapturePacket with MIT License 4 votes vote down vote up
public CaptureEntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new CaptureEntryViewHolder(parent.getContext(),mEntryTabDelegate);
Example 20
Source File:    From UniversalAdapter with Apache License 2.0 4 votes vote down vote up
protected VanillaHolder onCreateViewHolder(ViewGroup parent, int itemType) {
    return new VanillaHolder(new View(parent.getContext()));