1.

package com.multak.cookaraclient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import com.multak.cookaraclient.R;
import com.multak.cookaraclient.info.MusicInfo; import java.util.List; /**
* Created by guoxw on 2017/6/19.
*/ public class ProRecycleViewAdapter extends RecyclerView.Adapter<ProRecycleViewAdapter.ViewHolder> implements View.OnClickListener { private static final String TAG = "ProRecycleViewAdapter";
/**
*
*/
private ProRecycleViewAdapter.OnItemClickListener mOnItemClickListener=null;
List<MusicInfo> data;
Context context;
int type;
/**
* 点击的条目
*/
int num=-2;
public void textSize(int type){
this.type=type;
} public ProRecycleViewAdapter(List<MusicInfo> data, Context context) {
this.data = data;
this.context = context;
} @Override
public ProRecycleViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view= LayoutInflater.from(context).inflate(R.layout.prorecycleview_item_layout,parent,false);
final ProRecycleViewAdapter.ViewHolder holder=new ProRecycleViewAdapter.ViewHolder(view); /**
*
*/
view.setOnClickListener(this);
return holder; } @Override
public void onBindViewHolder(ProRecycleViewAdapter.ViewHolder holder, int position) { MusicInfo musicInfo=data.get(position);
holder.textView_SongName.setText(musicInfo.getMusicName());
holder.textView_SongSinger.setText(musicInfo.getMusicSinger());
int x=position+1;
holder.textView_no.setText(""+x);
if(type==2){
holder.textView_SongName.setTextColor(context.getResources().getColor(R.color.colorHomeText));
holder.textView_SongSinger.setTextColor(context.getResources().getColor(R.color.colorHomeText));
}else if(type==1){
holder.textView_SongName.setTextColor(context.getResources().getColor(R.color.colorSingerName));
holder.textView_SongSinger.setTextColor(context.getResources().getColor(R.color.colorSingerName)); } if(num==position){ Log.d(TAG, "onBindViewHolder: NUM: "+num);
Log.d(TAG, "onBindViewHolder: Position: "+position);

holder.textView_SongName.setTextColor(context.getResources().getColor(R.color.colorAccent));
}
    else {
        //恢复
      } /**
*
*/
holder.itemView.setTag(position);
} @Override
public int getItemCount() {
return data.size();
} class ViewHolder extends RecyclerView.ViewHolder{
View viewItem;
TextView textView_no;
TextView textView_SongName,textView_SongSinger;
public ViewHolder(View itemView) {
super(itemView);
viewItem=itemView;
textView_SongName= (TextView) itemView.findViewById(R.id.textView_SongName);
textView_SongSinger= (TextView) itemView.findViewById(R.id.textView_SongSinger);
textView_no= (TextView) itemView.findViewById(R.id.textView_no);
} } /**
*
* @param
*/
public static interface OnItemClickListener{
void onItemClick(View view,int position); }
/**
*
* @param v
*/
@Override
public void onClick(View v) { if(mOnItemClickListener != null) {
mOnItemClickListener.onItemClick(v,(int)v.getTag());
}
} /**
*
* @param listener
*/
public void setOnItemClickListener(ProRecycleViewAdapter.OnItemClickListener listener) {
this.mOnItemClickListener=listener;
} public void setItemClickColor(int num){
this.num=num;
} }

2.

package com.multak.cookaraclient.fragment;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView; import com.multak.cookaraclient.R;
import com.multak.cookaraclient.adapter.ProRecycleViewAdapter;
import com.multak.cookaraclient.info.MusicInfo;
import com.multak.cookaraclient.info.ToastUtils; import java.util.ArrayList;
import java.util.List; /**
* A simple {@link Fragment} subclass.
*/
public class ProFragment extends Fragment { private static final String TAG = "ProFragment";
View view;
RecyclerView recyclerView;
ProRecycleViewAdapter proRecycleAdapter;
List<MusicInfo>data=new ArrayList<>();
public ProFragment() {
// Required empty public constructor
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view=inflater.inflate(R.layout.fragment_pro, container, false);
recyclerView= (RecyclerView) view.findViewById(R.id.recycleView_Pro);
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
final Context context=getActivity();
addMusicInfo();
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
proRecycleAdapter=new ProRecycleViewAdapter(data,context);
recyclerView.setAdapter(proRecycleAdapter);
proRecycleAdapter.setOnItemClickListener(new ProRecycleViewAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) { ToastUtils.showtoast(getActivity(),""+position);
Log.d(TAG, "onBindViewHolder: TOAST: "+position);
proRecycleAdapter.setItemClickColor(position);
proRecycleAdapter.notifyDataSetChanged();
}
});
return view;
} public void addMusicInfo(){
data.add(new MusicInfo("我知道","阎韦伶"));
data.add(new MusicInfo("千里之外","周杰伦"));
data.add(new MusicInfo("同桌的你","老狼"));
data.add(new MusicInfo("我知道","阎韦伶"));
data.add(new MusicInfo("千里之外","周杰伦"));
data.add(new MusicInfo("同桌的你","老狼"));
data.add(new MusicInfo("我知道","阎韦伶"));
data.add(new MusicInfo("千里之外","周杰伦"));
data.add(new MusicInfo("同桌的你","老狼"));
data.add(new MusicInfo("我知道","阎韦伶"));
data.add(new MusicInfo("千里之外","周杰伦"));
data.add(new MusicInfo("同桌的你","老狼"));
data.add(new MusicInfo("我知道","阎韦伶"));
data.add(new MusicInfo("千里之外","周杰伦"));
data.add(new MusicInfo("同桌的你","老狼"));
data.add(new MusicInfo("我知道","阎韦伶"));
data.add(new MusicInfo("千里之外","周杰伦"));
data.add(new MusicInfo("同桌的你","老狼")); } public void selectOperate(final int posi,View view){ View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_song, null);
final PopupWindow popupWindow = new PopupWindow(contentView,600, LinearLayout.LayoutParams.WRAP_CONTENT, true);
WindowManager manager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
TextView textView_xiai= (TextView) contentView.findViewById(R.id.textView_xiai);
TextView textView_yuyue= (TextView) contentView.findViewById(R.id.textView_yuyue);
TextView textView_zhiding= (TextView) contentView.findViewById(R.id.textView_zhiding);
TextView textView_bofang= (TextView) contentView.findViewById(R.id.textView_bofang);
textView_xiai.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showtoast(getActivity(),"喜爱操作");
popupWindow.dismiss();
}
});
textView_yuyue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showtoast(getActivity(),"预约操作");
popupWindow.dismiss();
}
});
textView_zhiding.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showtoast(getActivity(),"置顶操作");
popupWindow.dismiss();
}
});
textView_bofang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showtoast(getActivity(),"播放操作");
popupWindow.dismiss();
}
});
int popupWidth = view.getMeasuredWidth();
int popupHeight = view.getMeasuredHeight();
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1]; Log.d(TAG, "selectOperate: 坐标:"+x+"&&"+y);
popupWindow.setTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.showAtLocation(view, Gravity.TOP|Gravity.LEFT, x+200, y+140);
popupWindow.showAsDropDown(view);
view.setAlpha(1f);
}
}

3.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="80dp">
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:textSize="@dimen/songnumbersize"
android:gravity="center"
android:textColor="@color/colorSingerName"
android:id="@+id/textView_no"/>
<LinearLayout
android:layout_marginLeft="@dimen/imagemagintext"
android:layout_height="50dp"
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/textView_SongName"
android:layout_width="match_parent"
android:layout_height="30dp"
android:paddingTop="5dp"
android:gravity="center_vertical"
android:textColor="@color/colorSongName"
android:textSize="@dimen/songnamesize"/>
<TextView
android:id="@+id/textView_SongSinger"
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center_vertical"
android:textColor="@color/colorSongName"
android:textSize="@dimen/songsingersize"/>
</LinearLayout>
</LinearLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.multak.cookaraclient.fragment.ProFragment"> <!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/recycleView_Pro"
android:textSize="23sp"
android:text="this is a ProFragment" /> </FrameLayout>

错误在于:在if()加入else{} 对item未选中做恢复操作。

<错误>的更多相关文章

  1. 简单物联网:外网访问内网路由器下树莓派Flask服务器

    最近做一个小东西,大概过程就是想在教室,宿舍控制实验室的一些设备. 已经在树莓上搭了一个轻量的flask服务器,在实验室的路由器下,任何设备都是可以访问的:但是有一些限制条件,比如我想在宿舍控制我种花 ...

  2. 利用ssh反向代理以及autossh实现从外网连接内网服务器

    前言 最近遇到这样一个问题,我在实验室架设了一台服务器,给师弟或者小伙伴练习Linux用,然后平时在实验室这边直接连接是没有问题的,都是内网嘛.但是回到宿舍问题出来了,使用校园网的童鞋还是能连接上,使 ...

  3. 外网访问内网Docker容器

    外网访问内网Docker容器 本地安装了Docker容器,只能在局域网内访问,怎样从外网也能访问本地Docker容器? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Docker容器 ...

  4. 外网访问内网SpringBoot

    外网访问内网SpringBoot 本地安装了SpringBoot,只能在局域网内访问,怎样从外网也能访问本地SpringBoot? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装Java 1 ...

  5. 外网访问内网Elasticsearch WEB

    外网访问内网Elasticsearch WEB 本地安装了Elasticsearch,只能在局域网内访问其WEB,怎样从外网也能访问本地Elasticsearch? 本文将介绍具体的实现步骤. 1. ...

  6. 怎样从外网访问内网Rails

    外网访问内网Rails 本地安装了Rails,只能在局域网内访问,怎样从外网也能访问本地Rails? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Rails 默认安装的Rails端口 ...

  7. 怎样从外网访问内网Memcached数据库

    外网访问内网Memcached数据库 本地安装了Memcached数据库,只能在局域网内访问,怎样从外网也能访问本地Memcached数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装 ...

  8. 怎样从外网访问内网CouchDB数据库

    外网访问内网CouchDB数据库 本地安装了CouchDB数据库,只能在局域网内访问,怎样从外网也能访问本地CouchDB数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Cou ...

  9. 怎样从外网访问内网DB2数据库

    外网访问内网DB2数据库 本地安装了DB2数据库,只能在局域网内访问,怎样从外网也能访问本地DB2数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动DB2数据库 默认安装的DB2 ...

  10. 怎样从外网访问内网OpenLDAP数据库

    外网访问内网OpenLDAP数据库 本地安装了OpenLDAP数据库,只能在局域网内访问,怎样从外网也能访问本地OpenLDAP数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动 ...

随机推荐

  1. 谷歌C++编程为何禁止缺省参数

    C++的缺省参数尽量不要使用,结果可能出乎我们的意料,下面的程序大家看看输出结果是多少? )                  cout << num << endl;     ...

  2. css—文字渐变色

    .text-gradient { display: inline-block; color: green; font-size: 10em; font-family: ´微软雅黑´; backgrou ...

  3. promise待看文档备份

    http://swift.gg/2017/03/27/promises-in-swift/ http://www.cnblogs.com/feng9exe/p/9043715.html https:/ ...

  4. 洛谷P1441 砝码称重 枚举 + 01背包

    显然,n<=20, m<=4 的数据范围一眼爆搜. 直接搜索一下不用哪4个砝码,再做一遍01背包即可. 可能是本人太菜鸡,01背包部分调了半天QAQ-- #include<cstdi ...

  5. tsar采集数据原理

    系统模块 cpu 字段含义 user: 表示CPU执行用户进程的时间,通常期望用户空间CPU越高越好. sys: 表示CPU在内核运行时间,系统CPU占用率高,表明系统某部分存在瓶颈.通常值越低越好. ...

  6. BZOJ 3158 千钧一发 (最大流->二分图带权最大独立集)

    题面:BZOJ传送门 和方格取数问题很像啊 但这道题不能像网格那样黑白染色构造二分图,所以考虑拆点建出二分图 我们容易找出数之间的互斥关系,在不能同时选的两个点之间连一条流量为$inf$的边 由于我们 ...

  7. P1892 团伙

    题目描述 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么他们要么是朋友,要么是敌人.而且有一点是肯定的,就是: 我朋友的朋友是我的朋友: 我敌人的敌人也是我的朋友. 两个强盗是同一团伙的 ...

  8. [USACO17JAN]Promotion Counting

    线段树合并. 正解好像不是线段树合并,但是出于练手的目的写了线段树合并. 大概就是对于左右子树,如果有一个为空,返回非空的,如果都不为空,就把这两个整合到一起就行了. #include <ios ...

  9. 批量删除.svn目录

    find . -type d -name ".svn"|xargs rm -rf find . -type d -iname ".svn" -exec rm - ...

  10. maven 依赖的传递性

    1.如图我们有三个项目,项目Age,项目Bge,项目Cge 2.我们使Age项目依赖到Bge项目,Bge项目依赖到Cge项目 Age项目和Bge项目分别执行命令:mvn install  打包*.ja ...