Java Code Examples for android.databinding.ViewDataBinding#getRoot()

The following examples show how to use android.databinding.ViewDataBinding#getRoot() . 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: HeaderedRecyclerViewDatabindingAdapter.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 6 votes vote down vote up
@Override
public BindingHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
    if (viewType == TYPE_HEADER) {
        final ViewDataBinding headerBinding =
                DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                        headerParams.headerLayoutId, parent, false);

        final BindingHolder holder = new BindingHolder(headerBinding.getRoot());
        holder.setBinding(headerBinding);

        if (parent instanceof RecyclerView) {
            prepareHeaderLayout((RecyclerView) parent, holder);
        }

        return holder;
    }

    return super.onCreateViewHolder(parent, viewType);
}
 
Example 2
Source File: OpenAPISAdapter.java    From WanAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected View getItemView(int layoutResId, ViewGroup parent) {
    ViewDataBinding binding;
    if (layoutResId == R.layout.item_open_api) {
        ItemOpenApiBinding b1 = DataBindingUtil.inflate(mLayoutInflater, layoutResId, parent, false);
        b1.setCallback((GeneralClickCallback<ThreeAPIBean.LinkBean>) mViewModel.mClickChildEvent::setValue);
        binding = b1;
    } else if (layoutResId == R.layout.item_open_api_section) {
        ItemOpenApiSectionBinding b2 = DataBindingUtil.inflate(mLayoutInflater, layoutResId, parent, false);
        binding = b2;
    } else {
        return super.getItemView(layoutResId, parent);
    }

    View view = binding.getRoot();
    view.setTag(com.xujiaji.mvvmquick.R.id.BaseQuickAdapter_databinding_support, binding);
    return view;
}
 
Example 3
Source File: SingleBindingAdapter.java    From all-base-adapter with Apache License 2.0 6 votes vote down vote up
/**
 * 不必关心从缓存取 还是inflate
 *
 * @param parent
 * @param layoutId
 * @return
 */
@Override
public ViewHolder getViewHolderByType(ViewGroup parent, int layoutId) {
    ViewHolder holder = mViewCache.get(layoutId);
    if (holder == null) {
        Log.d("TAG", "创建");
        ViewDataBinding binding = DataBindingUtil.inflate(mInflater, layoutId, parent, false);
        View itemView = binding.getRoot();
        ViewHolder holder2 = new ViewHolder(itemView, layoutId);
        itemView.setTag(R.id.zxt_tag_vh, holder2);
        itemView.setTag(R.id.zxt_tag_vdb, binding);
        return holder2;
    }
    Log.d("TAG", "复用");
    return holder;
}
 
Example 4
Source File: MyAdapter.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewDataBinding binding = null;
    if (convertView == null) {
        binding = DataBindingUtil.inflate(inflater, layoutResId, parent, false);

    }else{
        binding = DataBindingUtil.getBinding(convertView);
    }

    binding.setVariable(variableId,list.get(position));

    return binding.getRoot();
}
 
Example 5
Source File: ViewGroupBindings.java    From okuki with Apache License 2.0 5 votes vote down vote up
@BindingAdapter("component")
public static void loadComponent(ViewGroup viewGroup, MvvmComponent component) {
    if (component != null) {
        ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), component.getLayoutResId(), viewGroup, false);
        View view = binding.getRoot();
        binding.setVariable(BR.vm, component.getViewModel());
        binding.executePendingBindings();
        viewGroup.removeAllViews();
        viewGroup.addView(view);
    }
}
 
Example 6
Source File: BaseBindAdapter.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
protected View getItemView(int layoutResId, ViewGroup parent) {
    ViewDataBinding binding = DataBindingUtil.inflate(mLayoutInflater, layoutResId, parent, false);
    if (binding == null) {
        return super.getItemView(layoutResId, parent);
    }
    View view = binding.getRoot();
    view.setTag(R.id.BaseQuickAdapter_databinding_support, binding);
    return view;
}
 
Example 7
Source File: BindingAwareViewHolder.java    From moserp with Apache License 2.0 4 votes vote down vote up
public BindingAwareViewHolder(ViewDataBinding binding) {
    super(binding.getRoot());
    this.binding = binding;
}
 
Example 8
Source File: DataBindingViewFactory.java    From Pan with Apache License 2.0 4 votes vote down vote up
@Override
public View initWithoutView(Context context, ViewGroup parent, boolean attach, Class clazz) {
    ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), getLayout(clazz), parent, attach);
    return binding.getRoot();
}
 
Example 9
Source File: TrailersAdapter.java    From AndroidSchool with Apache License 2.0 4 votes vote down vote up
public ViewHolder(ViewDataBinding viewDataBinding) {
    super(viewDataBinding.getRoot());

    viewDataBinding.executePendingBindings();
    mDataBinding = viewDataBinding;
}
 
Example 10
Source File: ReviewsAdapter.java    From AndroidSchool with Apache License 2.0 4 votes vote down vote up
public ViewHolder(ViewDataBinding viewDataBinding) {
    super(viewDataBinding.getRoot());

    viewDataBinding.executePendingBindings();
    mDataBinding = viewDataBinding;
}
 
Example 11
Source File: RecyclerViewBA.java    From chaoli-forum-for-android-2 with GNU General Public License v3.0 4 votes vote down vote up
MyViewHolder(ViewDataBinding binding) {
    super(binding.getRoot());
    this.binding = binding;
}
 
Example 12
Source File: OnlyViewHolder.java    From NoAdapter with Apache License 2.0 4 votes vote down vote up
OnlyViewHolder(ViewDataBinding binding, ExtraBinding extraBinding) {
  super(binding.getRoot());
  this.binding = binding;
  this.extraBinding = extraBinding;
}
 
Example 13
Source File: BindingRecyclerViewAdapter.java    From SimpleFTP with MIT License 4 votes vote down vote up
/**
 * Default constructor
 * @param binding The item binding.
 */
ViewHolder(ViewDataBinding binding)
{
    super(binding.getRoot());
    this.binding = binding;
}
 
Example 14
Source File: RecyclerViewAdapter.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
public DataBindingViewHolder(@NonNull ViewDataBinding viewBinding) {
    super(viewBinding.getRoot());
    this.viewBinding = viewBinding;
}
 
Example 15
Source File: ArrayAdapter.java    From Villains-and-Heroes with Apache License 2.0 4 votes vote down vote up
public ViewHolder(ViewDataBinding binding) {
    super(binding.getRoot());
    mBinding = binding;
    mBinding.getRoot().setOnClickListener(this);
}
 
Example 16
Source File: SimpleBindingListAdapter.java    From Walrus with GNU General Public License v3.0 4 votes vote down vote up
BindingViewHolder(ViewDataBinding viewDataBinding, int viewType) {
    super(viewDataBinding.getRoot());

    this.viewDataBinding = viewDataBinding;
    this.viewType = viewType;
}
 
Example 17
Source File: BaseBindingListAdapter.java    From GracefulMovies with Apache License 2.0 4 votes vote down vote up
BaseBindingVH(ViewDataBinding binding) {
    super(binding.getRoot());

    this.binding = binding;
}
 
Example 18
Source File: BaseAdapter.java    From Sunshine with Apache License 2.0 4 votes vote down vote up
BaseViewHolder(ViewDataBinding viewDataBinding) {
    super(viewDataBinding.getRoot());
    this.viewDataBinding = viewDataBinding;
}
 
Example 19
Source File: MyBaseAdapter.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public MyViewHolder(ViewDataBinding binding) {
        super(binding.getRoot());
        this.binding = binding;
}
 
Example 20
Source File: StoryAdapter.java    From Idaily with Apache License 2.0 4 votes vote down vote up
public static StoryViewHolder createViewHolder(ViewDataBinding binding) {
    return new StoryViewHolder(binding.getRoot(), binding);
}