Xrecycleview下拉刷新,上啦加载,点击跳转

//Adapter
public classApdteextendsRecyclerView.Adapter {
private Context context;
private List<String> list;
public Apdte(Context context,List<String> list ){
this.context= context;
this.list= list;
}
public Apdte() {
super();
}
public MyApdate onCreate ViewHolder(ViewGroup parent, intviewType) {
View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_header,parent, false);
MyApdate myApdate =newMyApdate(view);
return myApdate;
}
@Override
public void onBindViewHolder(MyApdate holder, intposition) {
holder.tt.setText(list.get(position));
holder.tt.setOnClickListener(newView.OnClickListener() {
@Override
public void onClick(View v) {
Intent in =newIntent(v.getContext(),Second_Activity.class);
Log.d("ssss","单个的");
v.getContext().startActivity(in);
}
});
}
@Override
public intgetItemCount() {
return list.size();
}
}
class MyApdate extends RecyclerView.ViewHolder {
TextView tt;
public MyApdate(finalView itemView) {
super(itemView);
tt= (TextView) itemView.findViewById(R.id.TextView);
itemView.setOnClickListener(newView.OnClickListener() {
@Override
public voidonClick(View v) {
Intent in =new Intent(itemView.getContext(),Second_Activity.class);
Log.d("ssss","全部的");
itemView.getContext().startActivity(in);
}
});
}
}
//主activity
public classMainActivityextendsAppCompatActivity {
privateXRecyclerViewxx;
privateApdteaa;
privateListlist;
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xx= (XRecyclerView) findViewById(R.id.XRecyclerView);
LinearLayoutManager layoutManager =newLinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
xx.setLayoutManager(layoutManager);
list=newArrayList<>();
for(inti =0;i <20;i++) {
list.add("第"+ i +"--------");
}
aa=newApdte(MainActivity.this,list);
xx.setAdapter(aa);
xx.setLoadingListener(newXRecyclerView.LoadingListener() {
@Override
public voidonRefresh() {
// list.clear();
for(inti =0;i <20;i++) {
list.add("第"+ i +"条数据");
}
aa=newApdte(MainActivity.this,list);
aa.notifyDataSetChanged();
xx.refreshComplete();
}
@Override
public voidonLoadMore() {
list.add("新家的");
for(inti =0;i <10;i++) {
list.add("第"+ i +"条数据");
}
aa.notifyDataSetChanged();
xx.loadMoreComplete();
}
});
}
}
主布局

Item根布局一定要给一个高度

导包


apply plugin:'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.bawei.xrecycleView"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir:'libs',include: ['*.jar'])
testCompile'junit:junit:4.12'
compile'com.android.support:appcompat-v7:25.1.0'
compile'com.jcodecraeer:xrecyclerview:1.3.2'
}
-----------------------------------------------------------------------------------------
