当前位置: 首页>>代码示例>>Java>>正文


Java ViewDataBinding.setVariable方法代码示例

本文整理汇总了Java中android.databinding.ViewDataBinding.setVariable方法的典型用法代码示例。如果您正苦于以下问题:Java ViewDataBinding.setVariable方法的具体用法?Java ViewDataBinding.setVariable怎么用?Java ViewDataBinding.setVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.databinding.ViewDataBinding的用法示例。


在下文中一共展示了ViewDataBinding.setVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
    vm = new MainViewModel();
    binding.setVariable(BR.vm, vm);
    binding.executePendingBindings();
}
 
开发者ID:wongcain,项目名称:okuki,代码行数:9,代码来源:MainActivity.java

示例2: convert

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void convert(MovieViewHolder helper, Movie item) {
    ViewDataBinding binding = helper.getBinding();
    binding.setVariable(BR.movie, item);
    binding.setVariable(BR.presenter, mPresenter);
    binding.executePendingBindings();
    switch (helper.getLayoutPosition() %
            2) {
        case 0:
            helper.setImageResource(R.id.iv, R.mipmap.m_img1);
            break;
        case 1:
            helper.setImageResource(R.id.iv, R.mipmap.m_img2);
            break;

    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DataBindingUseAdapter.java

示例3: convert

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void convert(BaseBindHolder helper, WeatherDailyResponse.DailyResult.Daily item) {
    ViewDataBinding binding = helper.getBinding();
    binding.setVariable(BR.daily, item);
    binding.executePendingBindings();

    SuperTextView superTextView = helper.getView(R.id.super_item_daily);
    ArmsUtils.INSTANCE.obtainArmsComponent(mContext).imageLoader()
            .loadImage(mContext,
                    ImageConfigImpl.builder()
                            .url(String.format(Locale.CHINESE, Api.API_WEATHER_ICON_URL, item.getCodeDay()))
                            .placeholder(R.mipmap.ic_placeholder)
                            .errorPic(R.mipmap.weather_unknown)
                            .transformation(new FitCenter())
                            .imageView(superTextView.getRightIconIV())
                            .build());
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:18,代码来源:WeatherDailyAdapter.java

示例4: onCreateRealViewHolder

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
public RecyclerView.ViewHolder onCreateRealViewHolder(ViewGroup parent, int viewType) {
    ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.ext_adapter_item, parent, false);
    //添加监听器
    binding.setVariable(BR.adapter, this);
    ItemViewHolder holder = new ItemViewHolder(binding.getRoot());
    holder.setBinding(binding);
    return holder;
}
 
开发者ID:conghaonet,项目名称:recyclerview-ext,代码行数:10,代码来源:MyExtAdapter.java

示例5: bind

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
private static void bind(ViewGroup viewGroup, ItemView itemView, List<?> viewModelList, final OnItemClickListener<?> onItemClickListener) {
    if (viewModelList != null && !viewModelList.isEmpty()) {
        viewGroup.removeAllViews();
        for (int pos=0; pos<viewModelList.size(); pos++) {
            final Object viewModel = viewModelList.get(pos);
            final ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()),
                    itemView.layoutRes(), viewGroup, true);
            binding.setVariable(itemView.bindingVariable(), viewModel);

            setListener(onItemClickListener, ViewHolder.createViewHolder(viewGroup.getContext(), binding.getRoot()), viewModel, pos);
        }
    }
}
 
开发者ID:fashare2015,项目名称:MVVM-JueJin,代码行数:14,代码来源:ViewGroupAdapter.java

示例6: onBindViewHolder

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(DataBindingViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    ViewDataBinding binding = holder.getBinding();
    binding.setVariable(BR.listener, mStoryListener);
    binding.executePendingBindings();
}
 
开发者ID:nicholasrout,项目名称:shortstories,代码行数:8,代码来源:StoryAdapter.java

示例7: onCreate

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currency_details);
    binding.setVariable(BR.model, mViewModel);
    if (!isRetained(savedInstanceState)) {
        final String currencyCode = getIntent().getStringExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE);
        Bundle bundle = new Bundle();
        bundle.putString(CurrencyDetailsViewModel.KEY_CURRENCY_CODE, currencyCode);
        mViewModel.onLoad(bundle);
    }
}
 
开发者ID:krokers,项目名称:exchange-rates-mvvm,代码行数:13,代码来源:CurrencyDetailsActivity.java

示例8: onCreate

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currencies);
    binding.setVariable(BR.model, mViewModel);
    if (!isRetained(savedInstanceState)) {
        mViewModel.onLoad(null);
    }
}
 
开发者ID:krokers,项目名称:exchange-rates-mvvm,代码行数:10,代码来源:CurrenciesActivity.java

示例9: loadComponent

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:wongcain,项目名称:okuki,代码行数:12,代码来源:ViewGroupBindings.java

示例10: bind

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
private static void bind(RecyclerView container, final ItemView item, final List<?> datas,
                        final List<? extends ItemView> header, final List<?> headerDatas,
                        final OnItemClickListener<?> onItemClickListener) {


    RecyclerView.Adapter<?> adapter;
    if (datas != null) {
        // set default LayoutManager.
        if(container.getLayoutManager() == null)
            setLayoutManager(container, LayoutManagers.linear());

        adapter = container.getAdapter();
        if(adapter == null) {

            // initialize, adapter is only set once !!!
            CommonRvAdapter innerAdapter;
            container.setAdapter(adapter = new HeaderAndFooterWrapper<>(innerAdapter = new CommonRvAdapter<Object>(container.getContext(), item.layoutRes(), (List<Object>)datas) {
                @Override
                protected void convert(ViewHolder holder, Object data, int position) {
                    DataBindingUtil.bind(holder.itemView).setVariable(item.bindingVariable(), data);
                }
            }));
            innerAdapter.setOnItemClickListener(onItemClickListener);

            // add headers !!!
            if (header!=null && headerDatas != null) {
                HeaderAndFooterWrapper headerAdapter = (HeaderAndFooterWrapper) adapter;
                headerAdapter.removeHeaderViews();
                for (int i = 0; i < header.size() && i < headerDatas.size(); i++) {
                    ItemView _itemView = header.get(i);
                    Object _data = headerDatas.get(i);
                    LayoutInflater inflater = LayoutInflater.from(container.getContext());

                    ViewDataBinding binding = DataBindingUtil.inflate(inflater, _itemView.layoutRes(), container, false);
                    headerAdapter.addHeaderView(binding.getRoot());
                    binding.setVariable(_itemView.bindingVariable(), _data);
                }
            }
        }

        adapter.notifyDataSetChanged();
    }
}
 
开发者ID:fashare2015,项目名称:MVVM-JueJin,代码行数:44,代码来源:RecyclerViewAdapter.java

示例11: onBindViewHolder

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
private void onBindViewHolder(ViewDataBinding dataBinding, Object data) {
    //还可以写一些其他的绑定业务逻辑......
    dataBinding.setVariable(BR.itemData, data);
}
 
开发者ID:free46000,项目名称:MultiItem,代码行数:5,代码来源:DataBindActivity.java

示例12: onBindViewHolder

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void onBindViewHolder(ViewDataBinding dataBinding, ItemEmptyAndError data) {
    dataBinding.setVariable(BR.itemData, data);
}
 
开发者ID:free46000,项目名称:MultiItem,代码行数:5,代码来源:ItemEmptyAndError.java

示例13: initInputView

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void initInputView(ViewDataBinding dataBinding) {
    //把自身实例对象通过ViewDataBinding绑定到视图中
    dataBinding.setVariable(BR.itemData, this);
}
 
开发者ID:free46000,项目名称:MultiItem,代码行数:6,代码来源:ItemInfoDataBind.java

示例14: convert

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
@Override
protected void convert(BaseBindHolder helper, TextContent item) {
    ViewDataBinding binding = helper.getBinding();
    binding.setVariable(BR.content, item);
    binding.executePendingBindings();
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:7,代码来源:RtoAdapter.java

示例15: attachData

import android.databinding.ViewDataBinding; //导入方法依赖的package包/类
/**
 * This method attaches data to the layout file.
 * <p>
 * The name of the variable is <strong>"data"</strong> generally.
 *
 * @param binding the binding of the layout resource file.
 */
private void attachData(ViewDataBinding binding) {
    binding.setVariable(BR.data, this);
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:11,代码来源:BaseViewModel.java


注:本文中的android.databinding.ViewDataBinding.setVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。