Java Code Examples for androidx.databinding.DataBindingUtil#bind()

The following examples show how to use androidx.databinding.DataBindingUtil#bind() . 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: BaseDialog.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    if (parentView == null) {
        initLayout();
        parentView = LayoutInflater.from(mContext).inflate(mLayoutID, null);
        baseBind = DataBindingUtil.bind(parentView);
        initView(parentView);
        initData();
    }
    builder.setView(parentView);
    return builder.create();
}
 
Example 2
Source File: DataBindingDialogFragment.java    From AndroidNavigation with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_data_binding, container, false);

    FragmentDataBindingBinding bindingBinding = DataBindingUtil.bind(root.getChildAt(0));

    User user = new User();
    user.setFirstName("Jack");
    user.setLastName("Ma");
    bindingBinding.setUser(user);

    return root;
}
 
Example 3
Source File: MainActivity.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * inflateHeaderView 进来的布局要宽一些
 */
private void initDrawerLayout() {
    bindingView.navView.inflateHeaderView(R.layout.nav_header_main);
    View headerView = bindingView.navView.getHeaderView(0);
    bind = DataBindingUtil.bind(headerView);
    bind.setViewModel(viewModel);
    bind.dayNightSwitch.setChecked(SPUtils.getNightMode());
    viewModel.isReadOk.set(SPUtils.isRead());

    GlideUtil.displayCircle(bind.ivAvatar, ConstantsImageUrl.IC_AVATAR);
    bind.llNavExit.setOnClickListener(this);
    bind.ivAvatar.setOnClickListener(this);

    bind.llNavHomepage.setOnClickListener(listener);
    bind.llNavScanDownload.setOnClickListener(listener);
    bind.llNavDeedback.setOnClickListener(listener);
    bind.llNavAbout.setOnClickListener(listener);
    bind.llNavLogin.setOnClickListener(listener);
    bind.llNavCollect.setOnClickListener(listener);
    bind.llInfo.setOnClickListener(listener);
    bind.llNavCoin.setOnClickListener(listener);
    bind.llNavAdmire.setOnClickListener(listener);
    bind.tvRank.setOnClickListener(listener);

    viewModel.getUserInfo();
    viewModel.getCoin().observe(this, new Observer<CoinUserInfoBean>() {
        @Override
        public void onChanged(@Nullable CoinUserInfoBean coinUserInfoBean) {
            if (coinUserInfoBean != null) {
                bind.tvUsername.setText(coinUserInfoBean.getUsername());
                bind.tvLevel.setText(String.format("Lv.%s", UserUtil.getLevel(coinUserInfoBean.getCoinCount())));
                bind.tvRank.setText(String.format("排名 %s", coinUserInfoBean.getRank()));
            } else {
                bind.tvUsername.setText("玩安卓登录");
                bind.tvLevel.setText("Lv.1");
                bind.tvRank.setText("");
            }
        }
    });
}
 
Example 4
Source File: PopularSubjectsAdapter.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (getItemViewType(position)) {
        case RowType.SUBJECT_ITEM:
            final SubjectModel model = popularSubjects.get(position);
            final SubjectItemBinding subjectItemBinding = DataBindingUtil.bind(holder.itemView);
            subjectItemBinding.tvSubjectName.setText(model.name);
            @DrawableRes final int imageRes = UiUtil.getDrawable(subjectItemBinding.ivSubjectLogo.getContext(), model.imageName);
            ImageUtils.setRoundedCornerImage(subjectItemBinding.ivSubjectLogo, imageRes);
            holder.itemView.setContentDescription(
                    holder.itemView.getResources().getString(R.string.browse_by_subject) + " " + model.name);
            break;
    }

}
 
Example 5
Source File: SubjectsAdapter.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.subject_item_grid, parent, false);
    }
    final SubjectModel model = getItem(position);
    final SubjectItemGridBinding subjectItemBinding = DataBindingUtil.bind(convertView);
    subjectItemBinding.tvSubjectName.setText(model.name);
    @DrawableRes final int imageRes = UiUtil.getDrawable(getContext(), model.imageName);
    ImageUtils.setRoundedCornerImage(subjectItemBinding.ivSubjectLogo, imageRes);
    convertView.setContentDescription(
            convertView.getResources().getString(R.string.browse_by_subject) + " " + model.name);
    return convertView;
}
 
Example 6
Source File: SubtypeMultiViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public SubtypeMultiViewHolder(View itemView){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
}
 
Example 7
Source File: CharsetViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public CharsetViewHolder(View itemView, IMELanguageWrapper wrapper){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
    this.wrapper = wrapper;
}
 
Example 8
Source File: SubtypeSingleViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public SubtypeSingleViewHolder(View itemView){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
}
 
Example 9
Source File: AddedSingleViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public AddedSingleViewHolder(View itemView){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
}
 
Example 10
Source File: AddedMultiViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public AddedMultiViewHolder(View itemView){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
}
 
Example 11
Source File: AddedMultiChildViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public AddedMultiChildViewHolder(View itemView){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
}
 
Example 12
Source File: ChooseSingleViewHolder.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public ChooseSingleViewHolder(View itemView){
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.itemView = itemView;
}
 
Example 13
Source File: ViewModelBrick.java    From brickkit-android with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BrickViewHolder createViewHolder(View itemView) {
    return new ViewModelBrickViewHolder(DataBindingUtil.bind(itemView));
}
 
Example 14
Source File: ActivityHistoryFragment.java    From Easer with GNU General Public License v3.0 4 votes vote down vote up
HistoryViewHolder(View itemView, WeakReference<Context> context) {
    super(itemView);
    binding = DataBindingUtil.bind(itemView);
    this.context = context;
}
 
Example 15
Source File: UserAdapter.java    From MasteringAndroidDataBinding with MIT License 4 votes vote down vote up
public UserHolder(View itemView) {
    super(itemView);
    mBinding = DataBindingUtil.bind(itemView);
}
 
Example 16
Source File: AccomplishmentListAdapter.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
public ItemViewHolder(@NonNull ViewGroup parent) {
    super(LayoutInflater.from(parent.getContext()).inflate(R.layout.accomplishment_item, parent, false));
    binding = DataBindingUtil.bind(itemView);
}