标签:android
RecyclerView 是 android-support-v7-21 版本中新增的一个 Widgets, 还有一个 CardView 会在下次介绍使用。
老的版本不支持,你可以跟新下载直接拷贝到libs里面使用
布局里面这样写
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="4"
android:scrollbars="horizontal" />
她的适配器adapter与baseadapter不同,主要区别在这
private class ListAdapterHolder extends
Adapter<ListAdapterHolder.ViewHolder> {
Context context;
public ListAdapterHolder(Context context) {
this.context = context;
}
@Override
public int getItemCount() {
// TODO Auto-generated method stub
return monitorTabBeans.size();
}
@Override
public ListAdapterHolder.ViewHolder onCreateViewHolder(
ViewGroup parent, int viewType) {
// TODO Auto-generated method stub final LayoutInflater mInflater =
// LayoutInflater.from(parent.getContext());
final LayoutInflater mInflater = LayoutInflater.from(parent
.getContext());
final View sView = mInflater.inflate(R.layout.item_tab, parent,
false);
return new ViewHolder(sView);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
// TODO Auto-generated method stub
holder.Moname.setText(monitorTabBeans.get(position).getName());
holder.Moname.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// holder.Moname.setTextColor(Color.BLUE);
for (int i = 0; i < monitorTabBeans.size(); i++) {
monitor_list.getChildAt(i).setBackgroundColor(
Color.WHITE);
}
monitor_list.getChildAt(position).setBackgroundColor(
Color.rgb(72, 210, 204));
monEntriesBean = monitorTabBeans.get(position)
.getDMonEntries();
myadapter.notifyDataSetChanged();
MongroupId = monitorTabBeans.get(position).getId()
.toString();
MonitorCenter.this.position = position;
new MonitorStartTask().execute();
}
});
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView Moname;
public ViewHolder(View view) {
super(view);
Moname = (TextView) view.findViewById(R.id.name);
}
}
}
适配器弄好就好listview一样了
效果如下
RecyclerView 横向的listview 直接解决你的自定义问题
标签:android
原文地址:http://blog.csdn.net/chenaini119/article/details/45094137