如何在android中获取itemview的背景知识

时间:2016-09-08 09:40:29

标签: android background

我的代码用于显示使用RecyclerView从数据库到FirebaseRecyclerAdapter的日程安排。当用户点击项目时,此项目将更改背景,当用户再次单击项目时,此项目将更改为默认背景。 所以我的问题是如何获得itemview的背景?以及如何与R.color.colorPrimaryDark进行比较。 这是我的代码

mAdapter = new FirebaseRecyclerAdapter<Schedule, ScheduleViewHolder>(Schedule.class, R.layout.item_schedule,
                ScheduleViewHolder.class, query) {
            @Override
            protected void populateViewHolder(final ScheduleViewHolder viewHolder, Schedule model, final int position) {
                final DatabaseReference scheduleRef = getRef(position);
                // Set click listener for the whole post view
                final String scheduleKey = scheduleRef.getKey();
                Log.d("ScheduleKey", scheduleKey);

                viewHolder.bindToSchedule(model);
                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        viewHolder.itemView.setBackground(ContextCompat.getDrawable(getActivity(), R.color.colorPrimaryDark));
                        viewHolder.txtName.setTextColor(getResources().getColor(R.color.white));
                        viewHolder.txtNumber.setTextColor(getResources().getColor(R.color.white));
                        viewHolder.txtAddress.setTextColor(getResources().getColor(R.color.white));
                        viewHolder.txtIconOri.setTextColor(getResources().getColor(R.color.white));
                        viewHolder.txtIconHere.setTextColor(getResources().getColor(R.color.white));
                    }
                });
            }
        };

1 个答案:

答案 0 :(得分:0)

您的解决方案可能是这样的:

select c.Name, sum(t.value)
from Categories c
join Items i on c.Id = i.CategoryId
join Transactions t on t.ItemId = i.Id
where datepart(YEAR, t.CreatedTime) = 2016 
        and datepart(MONTH, t.CreatedTime) = 2
group by c.Name

颜色可以获得背景颜色。