recyclerview点击字体变色

 
  
//activity
runOnUiThread(new Runnable() {
    @Override
    public void run() {
        final List list = myFenLeiZuoBean.getData();

        recyclerzuo_linear.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false));
        final MyFenLeiZuoAdapter adapter = new MyFenLeiZuoAdapter(getActivity(), list);
        recyclerzuo_linear.setAdapter(adapter);
	//recyclerview点击事件
        adapter.setFenLeiZuo(new ItemListenner() {
            @Override
            public void OnItemClick(int position) {
//获取当前的索引
                int myposition = position;
//传到适配器  (适配器调用方法)
                adapter.getIndex(myposition);
//刷新适配器
                adapter.notifyDataSetChanged();
               
            }

            @Override
            public void OnLongClick(int position) {

            }
        });
    }
});
 
  
//适配器部分方法(控件值)
 
  
@Override
public void onBindViewHolder(final MyFenLeiZuoHolder holder, final int position) {
    holder.text_titlefenleizuo.setText(list.get(position).getName());
    //holder.text_titlefenleizuo.setTextColor(Color.BLACK);

    if (position == myposition) {
        holder.text_titlefenleizuo.setTextColor(Color.RED);
    }else {
        holder.text_titlefenleizuo.setTextColor(Color.GRAY);
    }

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                
            itemListenner.OnItemClick(position);
        }
    });
    holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            itemListenner.OnLongClick(position);
            return true;
        }
    });
}
 
  
//这是在适配器里实现方法
 
  
public void getIndex(int myposition) {
    this.myposition = myposition;
}


 
  
 
  
 
 

你可能感兴趣的:(recyclerview点击字体变色)