Java Code Examples for android.databinding.DataBindingUtil#getBinding()

The following examples show how to use android.databinding.DataBindingUtil#getBinding() . 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: RepoAdapter.java    From Anago with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    RepoListItemBinding binding;
    if (convertView == null) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.repo_list_item, parent, false);
        binding.setViewModel(injector.repoListItemViewModel());
    } else {
        binding = DataBindingUtil.getBinding(convertView);
    }

    Repo repo = getItem(position).first;
    boolean starred = getItem(position).second;
    binding.getViewModel().repo.set(repo);
    binding.getViewModel().starred.set(starred);

    return binding.getRoot();
}
 
Example 2
Source File: ContentAdapter.java    From Anago with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ContentListItemBinding binding;
    if (convertView == null) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.content_list_item, parent, false);
        binding.setViewModel(injector.contentListItemViewModel());
    } else {
        binding = DataBindingUtil.getBinding(convertView);
    }

    ContentListItemViewModel viewModel = binding.getViewModel();
    viewModel.content.set(getItem(position));

    return binding.getRoot();
}
 
Example 3
Source File: IssueAdapter.java    From Anago with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    IssueListItemBinding binding;
    if (convertView == null) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.issue_list_item, parent, false);
        binding.setViewModel(injector.issueListItemViewModel());
    } else {
        binding = DataBindingUtil.getBinding(convertView);
    }

    IssueListItemViewModel viewModel = binding.getViewModel();
    viewModel.issue.set(getItem(position));

    return binding.getRoot();
}
 
Example 4
Source File: PullRequestAdapter.java    From Anago with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    PullRequestListItemBinding binding;
    if (convertView == null) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.pull_request_list_item, parent, false);
        binding.setViewModel(injector.pullRequestListItemViewModel());
    } else {
        binding = DataBindingUtil.getBinding(convertView);
    }

    PullRequestListItemViewModel viewModel = binding.getViewModel();
    viewModel.pullRequest.set(getItem(position));

    return binding.getRoot();
}
 
Example 5
Source File: CustomRecyclerViewAdapter.java    From YuanNewsForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
    public void onBindViewHolder(CustomViewHolder holder, int position) {
        NewsCustom newsCustom = newsCustoms.get(position);
        NewsFragmentPageItemBinding bind=DataBindingUtil.getBinding(holder.itemView);
        bind.setNewsCustom(newsCustom);
        String url=NewsAPI.BASE_IMAGE_URL+newsCustom.getImg();
//        LogUtil.v(url);
        Glide.with(context)
                .load(url)
                .error(R.mipmap.loaderror)
                .placeholder(R.mipmap.loading)
                .into(bind.newsItemImage);
    }
 
Example 6
Source File: LabelsAdapter.java    From YuanNewsForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(LabelsViewHolder holder, final int position) {
    final String tasteVo = tasteVos.get(position);
    LabelFragmentItemBinding binding=DataBindingUtil.getBinding(holder.itemView);
    binding.setLabel(tasteVo);
    binding.num.setText((position+1)+"");
    binding.btnDelete.setText("关注");
    binding.btnDelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onDeleteItemClick.onDelete(tasteVo,position);
        }
    });
}
 
Example 7
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 8
Source File: CollectionsAdapter.java    From 10000sentences with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    SentenceCollectionBinding binding;
    if (convertView == null) {
        binding = DataBindingUtil.inflate(inflater, R.layout.sentence_collection, parent, false);
    } else {
        binding = DataBindingUtil.getBinding(convertView);
    }

    final SentenceCollection collection = getItem(position);

    binding.setKnownLanguage(languages.get(collection.getKnownLanguage()));
    binding.setTargetLanguage(languages.get(collection.getTargetLanguage()));
    binding.setCollection(getItem(position));
    binding.getRoot().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CollectionActivity.start((BaseActivity) getContext(), collection.getCollectionID());
        }

    });

    return binding.getRoot();
}
 
Example 9
Source File: BaseRecyclerViewHolder.java    From AndroidSkinAnimator with MIT License 4 votes vote down vote up
public BaseRecyclerViewHolder(ViewGroup viewGroup, int layoutId) {
    super(DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), layoutId, viewGroup, false).getRoot());
    mBinding = DataBindingUtil.getBinding(this.itemView);
}
 
Example 10
Source File: DataBindItemInput.java    From MultiItem with Apache License 2.0 4 votes vote down vote up
@Override
protected void initInputView(BaseViewHolder holder) {
    ViewDataBinding dataBinding = DataBindingUtil.getBinding(holder.itemView);
    initInputView(dataBinding);
}
 
Example 11
Source File: BindViewHolderManager.java    From MultiItem with Apache License 2.0 4 votes vote down vote up
@Override
    public void onBindViewHolder(BaseViewHolder holder, T data) {
        ViewDataBinding dataBinding = DataBindingUtil.getBinding(holder.itemView);
        onBindViewHolder(dataBinding, data);
//        dataBinding.executePendingBindings();
    }
 
Example 12
Source File: CustomRecyclerViewAdapter.java    From YuanNewsForAndroid with Apache License 2.0 4 votes vote down vote up
public CustomViewHolder(View itemView) {
    super(itemView);
    NewsFragmentPageItemBinding binding = DataBindingUtil.getBinding(itemView);
    binding.ripple.setOnClickListener(this);//设置点击事件
}
 
Example 13
Source File: MainAdapter.java    From searchliveo with Apache License 2.0 4 votes vote down vote up
ContentMainItemBinding getBinding() {
    return DataBindingUtil.getBinding(itemView);
}