Java Code Examples for android.support.v7.widget.DividerItemDecoration#setDrawable()

The following examples show how to use android.support.v7.widget.DividerItemDecoration#setDrawable() . 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: NotificationActivity.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_notification);
  ButterKnife.bind(this);
  mNotifications = new ArrayList<>();
  DividerItemDecoration itemDecor = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
  Drawable drawable = getResources().getDrawable(R.drawable.notification_divider);
  itemDecor.setDrawable(drawable);
  mHandler = new Handler();
  notificationAdapter = new NotificationAdapter();
  recyclerView.setLayoutManager(new LinearLayoutManager(this));
  recyclerView.addItemDecoration(itemDecor);
  recyclerView.setAdapter(notificationAdapter);
  backBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      finish();
    }
  });
  listenToNotifications();
}
 
Example 2
Source File: SourceFragment.java    From NewsApp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    FragmentSourceBinding binding = DataBindingUtil.inflate(inflater,
            R.layout.fragment_source, container, false);

    setupViewModel();
    binding.rvSources.setAdapter(sourceAdapter);
    if (getContext() != null) {
        DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(getResources().getDrawable(R.drawable.recycler_view_divider));
        binding.rvSources.addItemDecoration(divider);
    }

    return binding.getRoot();
}
 
Example 3
Source File: TaskListFragment.java    From mvp-helpers with MIT License 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);

    final DividerItemDecoration itemDecoration = new DividerItemDecoration(getApplicationContext(), DividerItemDecoration.VERTICAL);
    itemDecoration.setDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.divider));

    taskListAdapter = new TaskListAdapter(getApplicationContext(), new ArrayList<>());
    taskListAdapter.setOnItemSelectedListener(this::handleItemSelected);

    taskListView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    taskListView.addOnScrollListener(new RecyclerViewScrollBehavior(newTaskButton));
    taskListView.setItemViewCacheSize(1024 * 24);
    taskListView.addItemDecoration(itemDecoration);
    taskListView.setItemAnimator(new DefaultItemAnimator());
    taskListView.setAdapter(taskListAdapter);
    taskListView.setHasFixedSize(true);

    taskListAdapter.notifyDataSetChanged();
}
 
Example 4
Source File: CustomDividerActivity.java    From ItemDecorationDemo with Apache License 2.0 5 votes vote down vote up
private void initView() {
    findViewById(R.id.btn_padding).setVisibility(View.GONE);
    rvTest = findViewById(R.id.rv_test);
    mAdapter = new SampleAdapter(createList());
    rvTest.setAdapter(mAdapter);
    rvTest.setLayoutManager(new LinearLayoutManager(this));
    DividerItemDecoration decoration = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
    decoration.setDrawable(getResources().getDrawable(R.drawable.divider_gradient));
    rvTest.addItemDecoration(decoration);
}
 
Example 5
Source File: SearchActivity.java    From scallop with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activityComponent.inject(this);

    if (presenter == null) {
        return;
    }
    presenter.attachView(this);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    resultsRecyclerView.setLayoutManager(layoutManager);
    DividerItemDecoration itemDecoration = new DividerItemDecoration(this,
            DividerItemDecoration.VERTICAL);
    itemDecoration.setDrawable(ContextCompat.getDrawable(this, R.drawable.recycler_divider));
    resultsRecyclerView.addItemDecoration(itemDecoration);
    searchResultAdapter = new SearchResultAdapter();
    resultsRecyclerView.setAdapter(searchResultAdapter);

    recyclerViewScrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {
        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            presenter.search(searchInput.getText().toString(), page);
        }
    };
    resultsRecyclerView.addOnScrollListener(recyclerViewScrollListener);
}
 
Example 6
Source File: BaseListFragment.java    From playa with MIT License 5 votes vote down vote up
@Override
public void onFragmentViewCreated() {
    super.onFragmentViewCreated();
    layoutManager = new LinearLayoutManager(context);
    recyclerView.setLayoutManager(layoutManager);
    DividerItemDecoration itemDecoration = new DividerItemDecoration(context,
            DividerItemDecoration.VERTICAL);
    Drawable drawable = ContextCompat.getDrawable(context, R.drawable.list_divider);
    itemDecoration.setDrawable(drawable);
    recyclerView.addItemDecoration(itemDecoration);
}
 
Example 7
Source File: NewsFragment.java    From NewsApp with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil
            .inflate(inflater, R.layout.news_fragment, container, false);
    RecyclerView recyclerView = binding.rvNewsPosts;
    recyclerView.setAdapter(newsAdapter);
    if (getContext() != null) {
        DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(getResources().getDrawable(R.drawable.recycler_view_divider));
        recyclerView.addItemDecoration(divider);
    }

    return binding.getRoot();
}
 
Example 8
Source File: HomeFragment.java    From POCenter with MIT License 5 votes vote down vote up
@Override
protected void initView(View view) {
    bind = DataBindingUtil.bind(view);

    // init recycler view
    homeAdapter = new HomeAdapter(new ArrayList<ProjectBean>(0));
    bind.rv.setAdapter(homeAdapter);
    bind.rv.setLayoutManager(new LinearLayoutManager(getContext()));
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
    dividerItemDecoration.setDrawable(getResources().getDrawable(R.drawable.shape_drive_line));
    bind.rv.addItemDecoration(dividerItemDecoration);

    initEvent();
}
 
Example 9
Source File: FindFragment.java    From POCenter with MIT License 5 votes vote down vote up
@Override
protected void initView(View view) {
    bind = DataBindingUtil.bind(view);

    // init recycler view
    findAdapter = new FindAdapter(new ArrayList<ProjectBean>(0));
    bind.rv.setAdapter(findAdapter);
    bind.rv.setLayoutManager(new LinearLayoutManager(getContext()));
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
    dividerItemDecoration.setDrawable(getResources().getDrawable(R.drawable.shape_drive_line));
    bind.rv.addItemDecoration(dividerItemDecoration);

    initEvent();
}
 
Example 10
Source File: MosqueFragment.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mPresenter.setView(this);
    mPresenter.getMosqueList(false);

    mRefreshLayout.setColorSchemeResources(R.color.colorAccent);
    mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mPresenter.getMosqueList(true);
        }
    });

    LinearLayoutManager llm = new LinearLayoutManager(getActivity());

    TypedArray ta = getActivity().obtainStyledAttributes(new int[] {R.attr.mosqueDividerDrawable});
    Drawable divider = ta.getDrawable(0);
    ta.recycle();

    DividerItemDecoration decor = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
    decor.setDrawable(divider);

    mRecyclerView.setLayoutManager(llm);
    mRecyclerView.addItemDecoration(decor);

    if (mRecyclerView.getAdapter() == null) mRecyclerView.setAdapter(mAdapter);

    Drawable drawable = mProgressView.getDrawable();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
}
 
Example 11
Source File: GanHuoPageFragment.java    From scallop with MIT License 4 votes vote down vote up
@Override
public void onFragmentViewCreated() {
    super.onFragmentViewCreated();

    if (presenter != null) {
        presenter.attachView(this);
    }

    String tabTitle = getArguments().getString("TITLE");
    categoryName = tabTitle.equals(getContext().getString(R.string.tab_title_all)) ? "all" : tabTitle;

    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    DividerItemDecoration itemDecoration = new DividerItemDecoration(getContext(),
            DividerItemDecoration.VERTICAL);
    itemDecoration.setDrawable(ContextCompat.getDrawable(getContext(),
            R.drawable.recycler_divider));
    recyclerView.addItemDecoration(itemDecoration);
    adapter = new GanhuoAdapter();
    recyclerView.setAdapter(adapter);

    recyclerViewScrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {
        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            adapter.setLoading();
            presenter.getGanHuo(categoryName, page);
        }
    };
    recyclerView.addOnScrollListener(recyclerViewScrollListener);

    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            presenter.getGanHuo(categoryName, 1);
            recyclerViewScrollListener.resetState();
            adapter.clear();
            adapter.resetFooter();
        }
    });
    refreshLayout.setRefreshing(true);
    presenter.getGanHuo(categoryName, 1);
}