首页 > 代码库 > RecyclerView的简单用法
RecyclerView的简单用法
package com.example.zhangmeng.recyclerview;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;public class MainActivity extends AppCompatActivity { private RecyclerView rv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); rv=new RecyclerView(this); setContentView(rv); rv.setLayoutManager(new LinearLayoutManager(this)); rv.setAdapter(new RecyclerView.Adapter() { class ViewHolder extends RecyclerView.ViewHolder{ private TextView tv; public ViewHolder(TextView itemView) { super(itemView); tv=itemView; } public TextView getTv() { return tv; } } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new ViewHolder(new TextView(parent.getContext())); } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh=(ViewHolder)holder; vh.getTv().setText("hello"+position); } @Override public int getItemCount() { return 10; } }); }}
RecyclerView的简单用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。