我有这个问题,我只想填写GridView的某些部分,具体取决于我给它的数字。这是图像:
如果我只提供8个中的3个,则应突出显示3个GridView
个项目。 请注意,8是固定的!我有所有代码和自定义适配器,我对哪个部分进行检查感到困惑,并且只应突出显示GridView
3个
这是我在我的活动中设置自定义适配器的地方:
Integer[] lessons = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8}; CustomAdapter gridViewAdapter = new CustomAdapter(this, R.layout.item_lessons, lessons); gridView.setAdapter(gridViewAdapter);
我的CustomAdapter:
@Override public View getView(final int position, View convertView, ViewGroup parent) { View row = convertView; ViewHolder holder = null; if (row == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); row = inflater.inflate(resource, parent, false); holder = new ViewHolder(); holder.tvLessons = (TextView) row .findViewById(R.id.lesson_module); row.setTag(holder); } else { holder = (ViewHolder) row.getTag(); } holder.tvLessons.setBackgroundResource(R.drawable.icon_lesson_filled); return row; } public class ViewHolder { public TextView tvLessons; }
答案 0 :(得分:1)
@Override public View getView(final int position, View convertView, ViewGroup parent) { View row = convertView; ViewHolder holder = null; if (row == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); row = inflater.inflate(resource, parent, false); holder = new ViewHolder(); holder.tvLessons = (TextView) row .findViewById(R.id.lesson_module); row.setTag(holder); } else { holder = (ViewHolder) row.getTag(); } holder.tvLessons.setBackgroundResource(R.drawable.icon_lesson_filled); if(position <= <yourNumber i.e 3>) holder.tvLesson.setBackgroundColor(Color.Blue); return row; } public class ViewHolder { public TextView tvLessons; }
如果您在实施时遇到任何问题,请与我们联系 享受...