package activity.cyq.com.learnrsv; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; /** * Created by DL_007 on 2015/7/19. */ class MyAdapter extends RecyclerView.Adapter { class ViewHolder extends RecyclerView.ViewHolder { private TextView txTitle; private TextView txContent; public ViewHolder(View root) { super(root); txTitle = (TextView) root.findViewById(R.id.title); txContent = (TextView) root.findViewById(R.id.content); } public TextView getTxTitle() { return txTitle; } public TextView getTxContent() { return txContent; } } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.listcell, null)); } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; Artical ac = data[position]; vh.getTxTitle().setText(ac.title); vh.getTxContent().setText(ac.content); } @Override public int getItemCount() { return data.length; } private Artical[] data = new Artical[]{ new Artical("标题一", "文章内容"), new Artical("标题一", "文章内容"), new Artical("标题一", "文章内容"), new Artical("标题一", "文章内容")}; }
时间: 2024-10-03 22:32:37